【发布时间】:2009-09-04 03:28:56
【问题描述】:
必须是一个简单的答案,但我不知所措,这是返回错误的代码。我试过带和不带斜线。
我不知道完整路径,我希望它是相对于 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();
}
谢谢
【问题讨论】:
-
您要打开的文件的完整路径是什么?