PDA

View Full Version : FileIO C++ Xcode




oxcug
Mar 19, 2012, 03:45 PM
Hey all, so I'm trying to open and write to a file. Here is my code:

ofstream ofile;
ofile.open("mySample.txt");
ofile << "Hello World, I am FileIO.\n\nP.S Luke I'm your Father";
ofile.close();

The Problem is that even though I am flushing the buffer with .close, It's not even creating the File anywhere on my disk. Anyone know what's wrong here?



subsonix
Mar 19, 2012, 04:04 PM
The Problem is that even though I am flushing the buffer with .close, It's not even creating the File anywhere on my disk. Anyone know what's wrong here?

It probably is creating a file, but in your working directory, which defaults to quite deep inside your Xcode project folder, where your executable file is. You can either change the working directory Xcode uses, or add an absolute path to the filename.

chown33
Mar 19, 2012, 04:40 PM
See this:
http://forums.macrumors.com/showthread.php?t=1285568