Does peek() on an already "EOF"ed ifstream continue to return EOF?
c++
Solution
The standard says about `peek`:
Returns: traits::eof() if good() is false.
When the stream's eofbit is set, `good()` will return `false` and therefore `peek` will return `traits::eof()`. This will continue to happen unless you perform an operation that clears the eofbit (such as seeking the stream). It will also return `traits::eof()` if the failbit or badbit are set.
Note: For the default `char`-based streams, `traits::eof()` is the same as `EOF`.
Problem
Simple code: ``` std::ifstream file("file.txt"); std::string line; while(getline(file,line)) ; //exhaust file //in this sample code, for simplicity assert that the only possible "fail" //is EOF (which it will always be under normal circumstances). assert(!file.fail() || file.eof()); assert(file.peek() == EOF); //does this always hold? ``` Will the final assert always succeed? Question rephrased: Does the location after EOF also return EOF? The documentation doesn't clearly mention what peek() does when the stream is ALREADY AT EOF, so hence my question.