我无法读取Xcode中的文件。我已经尝试了所有方法,包括将它们放在源代码,文档和产品文件夹中,以及将该文件与源代码放在同一文件夹中。代码如下:
#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();
}
而且输出中没有任何内容。任何建议,不胜感激。
最佳答案
在Xcode中,单击可执行文件并获取信息。在第一个标签中,应该有工作目录的设置。将您的example1.txt文件放在该文件夹中,或将工作目录更改为example1.txt的位置,您的代码应输出一些内容。
关于c++ - 无法在Xcode 3中打开文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8468547/