When not using binary mode (i.e. text mode) CRLF will be converted to LF, which means that the size provided by tellg() is no longer correct, and reading prematurely hits an EOF and sets the fail bit.