[英]std::ifstream not reading in after switching text editors from notepad++ to sublime text 2 for using the file it's reading in?
我从文件中读取了应用程序的一些数据,并且该数据最近停止工作。 我感觉它停止工作的时间与我从Notepad ++切换到Sublime Text 2的时间相对应...无论如何,这是我要读取数据的代码:
std::ifstream stream;
stream.open("parsing_model.txt");
char ignore_char;
std::string model_class;
int parsing_model;
while (stream >> model_class >> ignore_char >> parsing_model)
{
// snip
// doesn't even make it into a single run of this while loop.
}
我的数据组织为
Item1, 12
Item2, 4
foo, 42
bar, 1
文字编码中有东西吗? 如何使我的代码健壮地解决这个问题并解决我的问题? 直到最近,这段代码绝对可以工作几个月。 谢谢
使用流之前,请检查流是否处于良好状态。
stream.open("parsing_model.txt");
if (stream.good()) {
//... read the stream
} else {
std::cerr << "failed to open input file\n";
}
如果出现故障,请确保当前工作目录与保存输入文件的位置相同。 看来您正在Windows上运行,因此应该可以使用此命令查看当前目录。
system("dir & pause");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.