The next program what's wrong? I prefer the file reach the end.
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 reach the end of the file, but why not echo "eof is true".
The eof bit is only set (and thus eof() only returns true) if an actual read operation fails due to hitting the end of the file. A seek operation (apparently) isn't enough.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With