Note that file.rdbuf() is used to print the contents of file (see Section 15.14.3, page 846).
Thus, you operate directly on the stream buffer, which can’t manipulate the state of the stream. If
you print the contents of file by using the stream interface functions, such as getline() (see
Section 15.5.1, page 768), you’d have to clear() the state of file before it could be manipulated
in any way (including changes of the read position), because these functions set ios::eofbit and
ios::failbit when end-of-file is reached.