*** Stops reading at the first blank line.***
<<< Copied from microsoft.public.vc.language. >>>
Thank you, Mr Tandetnik.
g++ behaves the same way.
The only reason it appeared to work was that there were carriage returns
before the newline chars.
When I stripped the \r's, g++ set failbit too.
I'm not sure why basic_istream::get() works this way.
I would have prefered reading nothing, setting Line[0] to '\0', and
cin.gcount() == 0, without setting ios::failbit.
I'll bet people smarter than I debated it for months.
Can anyone explain why ios::failbit should be set in this case?
Here's updated code that works.
#include <iostream>
#include <limits>
using namespace std;
int main() {
static char Line[1024];
for (;;) {
if (!cin.get(Line, sizeof(Line))) {
if (cin.bad() || cin.eof())
break;
cin.clear();
}
cin.ignore(numeric_limits<int>::max(), '\n');
cout << ':' << Line << endl;
}
} // main
--
[ See
http://www.yqcomputer.com/ ]
[ comp.lang.c++.moderated. First time posters: Do this! ]