首先,这是我的代码的一部分:
....
string input;
getline(cin, input);
ifstream openFile;
openFile.open(input.c_str(), ios::in);
if(openFile.is_open()){
cout << "File opened" << endl;
}
else {
cout << "Cant open the file " << endl;
}
结果总是“无法打开文件”。我非常非常确定这些文件是存在的。我在同一目录中有data1.txt,data2.txt ... data10.txt(我使用XCode添加新的空文件,将数据添加到里面并保存)。
我做另一个测试,我创建一个新目录,复制粘贴 cpp 和数据文件。我在终端中运行,它可以工作,它可以读取数据文件。为什么 xcode 无法读取我的数据文件?任何想法?