C++ program infile won't open in xcode?
alt text http://img638.imageshack.us/img638/5731/screenshot20100613at121.png
Why does the c++ program produce the error shown? I'm especially confused since outfile opens without error yet infile displays the error? Both are defined in xcode exactly the same!! I've altering the "path type" setting without success. The open 开发者_开发技巧on infile always fails! Any suggestions would be very much appreciated!!
For those who responded thanks but as you can see but infile and outfile exist and are in the same location:
alt text http://img709.imageshack.us/img709/9316/screenshot20100613at123.png
- In Xcode, expand the "Targets" node and find your target. Given what I've seen, it'll be the only one there.
- Next, right-click on your project and add a new "Copy Files" build phase. When the dialog box comes up, make sure you set the Destination to "Products Directory".
- The new build phase will appear beneath your target with whatever name you gave it. Drag your in_file and out_file there.
- Compile and run.
In your current case out_file
would be created even if it doesn't exist (because you're using std::ofstream
).
in_file
, on the other hand, has to exist, and (I guess there is no such file in the directory with created binary), hence an error is produced.
Did you try launching your compiled application with the file in the same folder where the binary file is?
Probably there is no file named "in_file" in the program's working directory, so it can't be opened for reading.
For outfile
this doesn't matter since it is opened for writing and if it doesn't exist yet it will just be created.
The directory listing you posted doesn't show where the compiled executable is, but probably it will be somewhere in the build
directory. Probably this is then also its working directory and the place where the input file would need to be. (Look for the out_file
the program creates when it is run, it will be created in the working directory, the same directory where it searches for in_file
. And it is not the directory you posted the listing of, the out_file
there is too old.)
Turns out you have to specifically create the file here:
Project Path/build/Debug
apparently you can't just define it directly in the xcode project
精彩评论