OK, I fixed Test4. I need the istream::gcount() function:
Code:void Test4( ifstream& file ) { char block[BUFSIZ + 1]; string fileData; while ( file.read( block, BUFSIZ ) ) { fileData += block; } fileData.append( block, file.gcount() ); cout << "Test4 Bytes Read: " << fileData.size() << endl; }
I also fixed Test1() if anyone's still interested:
Now they all report the same size, except Test2() which is fatally broken, since it not only doesn't extract CRLF's, but it also doesn't extract spaces or any other whitespace.Code:void Test1( ifstream& file ) { string line; string fileData; while ( getline( file, line ) ) { fileData += line; if ( file.eof() == false ) { fileData += "\n"; } } cout << "Test1 Bytes Read: " << fileData.size() << endl; }
Thanks for all your comments. I am going with test1.