【发布时间】:2012-11-11 23:18:48
【问题描述】:
2012/11/13 更新: 我发现我的问题已经被问到了。 这是处理不同行尾文本文件的一个很好的解决方案: Getting std :: ifstream to handle LF, CR, and CRLF?
是否可以为 libstdc++ 做贡献?怎么样?
2012/11/11
我发现 cout 有问题。
如果 getline() 返回两个字符串,
第二个字符串将覆盖输出中的第一个字符串。
这是示例代码:
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
//normal code
cout << "Normal result:" << endl;
string str1 = "hello";
cout << str1;
str1 = "123";
cout << str1;
cout << endl;
//broken code
cout << "Bug?" << endl;
ifstream fin;
fin.open("test.dat");
string str;
getline(fin, str);
cout << str;
getline(fin, str);
cout << str;
fin.close();
return 0;
}
这里是输入文件(test.dat):
hello
123
输出将是:
Normal result:
hello123
Bug?
123lo
我使用的是 ubuntu 12.10 64 位,
编译器的版本是
g++ (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2.
有什么建议吗?
有没有人告诉我在哪里提交错误?
【问题讨论】:
-
更新:也许这不是一个错误,而是一个增强。有没有人可以告诉我在哪里提交这个问题?可以在 Bugzilla 上发帖吗?