I don't get it. :confused: eof() returns true if the eofbit is set, but the eofbit doesn't get set until you hit end of file while reading. Unless you test for end of file after the read, the order is wrong and you'll loop one too many times.
My bad, I should have been more explicit. Yes, I agree, feof( ) and eof( ) are not that great when compared to checking the stream state while reading files. But for small fixes I normally use:
#include <fstream>
#include <iostream>
#include <string>
int main()
{
using namespace std;
// Build a test file
{
ofstream os( "test.txt" );
os << "12345";
}
// Test the test file :)
ifstream is( "test.txt" );
int loopCount = 0;
char ch;
while (1 ) {
is.get( ch );
if( is.eof() ) break ;
++loopCount;
cout << ch << '\n';
}
cout << "Loop count: " << loopCount << '\n';
getchar( ) ;
return 0;
}
I'm surprised your little google groups didn't tell you that sos. Ha ha.
*sigh* Btw when are you turning 14 ?