问题打开文件c ++ [英] problem opening file c++
本文介绍了问题打开文件c ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
必须是一个简单的答案,但我失去了,这里是返回一个错误的代码。我尝试了和没有开始斜线。
Must be a simple answer but I am at a loss, here is the code that is returning an error. I have tried with and without the starting slash.
我不知道完整的路径,我想它是相对的,从exe,这是相对路径。我尝试转义斜杠。
I won't know the full path, I want it to be relative from the exe, and that is the relative path. I tried escaping the slashes.
我的问题是,我得到错误打开文件当文件存在。为什么会失败?
My problem is that i get "error opening file" when the file is there. why is it failing?
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()
。
What is your problem exactly?! if you want to test if the file is open or not use is_open()
.
这篇关于问题打开文件c ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文