I can’t get files in Xcode to be read. I’ve tried everything from putting them in the source, documentation and products folders and putting the file in the same folder as the source code. The code is as follows:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
string line;
ifstream infile;
infile.open ("example1.txt");
getline (infile,line);
cout << line << endl;
if (infile.is_open())
cout << "file opened successfully\n";
infile.close();
}
And nothing is printed in the output. Any suggestions are greatly appreciated.
In Xcode click on your executable and do a Get Info. In the first tab there should be a setting for the working directory. Put your example1.txt file in that folder, or change the working directory to the location of example1.txt and your code should output something.