2012/11/13 Update: I found my question had already been asked. Here is a good solution for handling different line ending text files: Getting std :: ifstream to handle LF, CR, and CRLF?
Is it possible to contribute to libstdc++? How?
2012/11/11
I found there's something wrong with cout.
If there are two strings returned from getline(),
the second string will overwrite the first one in the output.
This is sample code:
#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;
}
And here is the input file (test.dat):
hello
123
The output will be:
Normal result:
hello123
Bug?
123lo
I'm using ubuntu 12.10 64-bit,
and the version of compiler is
g++ (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2.
Any advice?
Is there anyone tell me where to file a bug?