【发布时间】:2013-07-10 01:38:15
【问题描述】:
我有以下文件:
BB
7.501106 5.324115
7.997006 8.287983
11.314904 11.768281
...
我 100% 确定文件没问题,我什至在 vim 中用:set list 显示换行符:
BB$
7.501106 5.324115$
7.997006 8.287983$
11.314904 11.768281$
...
但是当我在第一行打开并阅读时,会发生一些奇怪的事情。我有以下代码:
std::ifstream file(filename);
std::string line;
if (!file.is_open()) {
std::cerr << "parseConfig: Error opening config file: " << filename << std::endl;
exit(1);
}
getline(file, line);
std::cout << "line is: <" << line << ">" << std::endl;
if (line.compare("BB")) {
std::cerr << "parseConfig: Error in config file, first line is not BB" << std::endl;
exit(1);
}
现在我知道文件已正确打开,因为我们一直到最终错误。
打印出来如下:
>ine is: <BB //What!!!?? Why did this happen?
parseConfig: Error in config file, first line is not BB
这让我觉得很奇怪,就好像文本文件中有回车一样。但我很确定没有。
有什么想法吗?
【问题讨论】: