New to Xcode Can't Open Files in C++

My C program reads a text file. When I put it into Xcode it fails. What's happening?

Make sure that the input.txt file is not in the project folders, but in the same folder as the compiled program. You can find this by right selecting the executable under the 'Products' folder in the left pane of Xcode and selecting "Show in finder" and then move your .txt file there, and run it again.

example image

File open failure! reading from a file, c++, xcode

From the tag you put to the question, I think you are using Xcode, right? You need to know where does Xcode output the executable, and your People.txt file needs to be put under the same folder as the executable. In Xcode, goto

Xcode > Preference > Locations

The path shown under "Derived Data", is where Xcode put executable. It's typically ~/Library/Developer/Xcode/DerivedData.

There you will probably find a lot of folders of your projects. Go into the folder corresponds to this project and goto Build/Products/Debug, then you will find your executable. What you can do is put your People.txt there.

OR your can add the full path of your "People.txt" file to your inputFile.open() method.



Related Topics



Leave a reply



Submit