When using fstream in cplusplus, what is wrong with this program

The following program, what is wrong? I prefer the file to go all the way.

ifstream file("main.cpp", ios::binary | ios::ate); if (file) { //fstream::pos_type size = file.tellg(); file.seekg(100, fstream::cur); if (file.eof()) { cout << "eof is true\n"; } } 

fstream reaches the end of the file, but why not repeat "eof is true".

+4
source share
1 answer

The eof bit is set only (and, therefore, eof () returns true) if the actual read operation failed due to the end of file. A search operation (apparently) is not enough.

+7
source

Source: https://habr.com/ru/post/1478954/


All Articles