必须是一个简单的答案,但我不知所措,这是返回错误的代码。我试过使用和不使用起始斜线。
我不会知道完整路径,我希望它是相对于 exe 的,也就是相对路径。我尝试转义斜杠。
我的问题是当文件存在时我得到“打开文件时出错”。为什么会失败?
ifstream myFile("/LOGS/ex090716.txt");
if (myFile.fail()) {cout << "Error opening file";}
else
{
cout << "File opened... \n";
//string line;
//while( getline(myFile, line) ) {
// cmatch results;
// regex rx("(p|q)(=)([^ %]*)");
// regex_search(line.c_str(), results, rx);
// string referringWords = results[3];
//}
myFile.close();
}
谢谢
最佳答案
你的问题到底是什么?!如果您想测试文件是否打开,请使用 is_open()
。
关于c++ - 打开文件 C++ 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1377078/