Christopher said:
The dumb-o-meter's pegging out today... What, if anything, is wrong
with the following code?
std::ifstream f( "myfile.txt" );
if( !f ) {
cerr << "Couldn't open file\n";
}
while( getline(f,s) ) {
cout << s << '\n';
}
I'd go paranoid and try
std::ifstream f( "myfile.txt",std::ios::in);
if( !f ) {
cerr << "Couldn't open file" << endl;
}
while( getline(f,s) ) {
cout << s << endl;
}
if it still doesn't work, then my crystall ball thinks
a) you have a serious flaw in some beyond-the-snippet code,
like a memory problem or, generally, an UB somewhere else.
b) you have cout/cerr redirected
or their goodbit is cleared.
c) myfile.txt is malformed (like by odd end-of-line translation, etc.)
d) try waiting until April the 2nd and see if it does better
if neither, then I'm stumped.
You could try inserting an infinite loop in either if or while
to see if it indeed starts to loop infinitely -- that way you'll
know it's your output that's broken, not the stream stuff. Or the
other way round, of course.
- J.