I'm running MSVC++ .NET 2003.
I've got a text file that I need to parse. I'm using std::getline, but I'm running into some problems with missing lines. Here's my code:
std::ifstream infile("myfile.txt");
std::string line;
while (std::getline(infile, line)) {
// Operate on line...
}
I've debugged the std::getline function and found that, under certain conditions (see next paragraph), assignments to the std::string object do not work as expected.
Here is some pretty simple code that reproduces the problem.
std::string s;
s = "abc"; // s is good
s = "abcdefghijklmno"; // s is good
s = "abc"; // s is good
s = "abcdefghijklmnop"; // s is good
s.erase(); // s is BAD
s = "abcdefghijklmnop"; // s is good again
s = "abcdefghijklmnopqrstuvwxyz"; // s is good
s = "abc"; // s is BAD again
s = "abcd"; // s is BAD
s = "abcde"; // s is BAD
s = "abcdefghijklmno"; // s is still BAD
s = "abcdefghijklmnop"; // s is good again
s.clear(); // oops! s is BAD
s = "abc"; // s is BAD
s = "abcdefghijklmnop"; // s is good
The problem seems to occur when transitioning from a string with 16 or more characters to a string with 15 or less characters.
The following link seems to talk about this problem somewhat, but I'm not seeing the assertion. Plus, it's for VC++ 5.0.
Can anyone else reproduce this problem? Is this a known bug? Is there a workaround? I'm simply amazed that this has not been found to date.
I've got a text file that I need to parse. I'm using std::getline, but I'm running into some problems with missing lines. Here's my code:
std::ifstream infile("myfile.txt");
std::string line;
while (std::getline(infile, line)) {
// Operate on line...
}
I've debugged the std::getline function and found that, under certain conditions (see next paragraph), assignments to the std::string object do not work as expected.
Here is some pretty simple code that reproduces the problem.
std::string s;
s = "abc"; // s is good
s = "abcdefghijklmno"; // s is good
s = "abc"; // s is good
s = "abcdefghijklmnop"; // s is good
s.erase(); // s is BAD
s = "abcdefghijklmnop"; // s is good again
s = "abcdefghijklmnopqrstuvwxyz"; // s is good
s = "abc"; // s is BAD again
s = "abcd"; // s is BAD
s = "abcde"; // s is BAD
s = "abcdefghijklmno"; // s is still BAD
s = "abcdefghijklmnop"; // s is good again
s.clear(); // oops! s is BAD
s = "abc"; // s is BAD
s = "abcdefghijklmnop"; // s is good
The problem seems to occur when transitioning from a string with 16 or more characters to a string with 15 or less characters.
The following link seems to talk about this problem somewhat, but I'm not seeing the assertion. Plus, it's for VC++ 5.0.
Can anyone else reproduce this problem? Is this a known bug? Is there a workaround? I'm simply amazed that this has not been found to date.