ふむふむ。
#include <iostream> #include <fstream> using namespace std; int main() { ofstream fout("foo.txt"); if (!fout.is_open()) { exit(1); } fout << "ABCDE"; fout.close(); ifstream fin("foo.txt"); if (!fin.is_open()) { exit(1); } fin.seekg(-1, ios::end); cout << "eof:" << boolalpha << fin.eof() << endl; cout << static_cast<char>(fin.get()) << endl; cout << "eof:" << boolalpha << fin.eof() << endl; cout << fin.get() << endl; cout << "eof:" << boolalpha << fin.eof() << endl; fin.close(); return 0; }
eof:false
E
eof:false
−1
eof:true