Answer the question
In order to leave comments, you need to log in
Why can't c++ programs see the file when run outside of xcode?
Good evening.
I have a program that needs to read values from a .txt file.
Checked in the program:
fromFile.open("words.txt");
if (!fromFile.is_open())
{
cout << "Could not open the file "<<endl;
cout << "Program terminating.\n";
exit(EXIT_FAILURE);
}
Answer the question
In order to leave comments, you need to log in
The program tries to look for a file in the current folder . In order for the program to look for a file in the same folder where its executable file is located, you need to take argv[0], strip the program name from it, put the file name in this place and use the resulting value.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question