The standard actually doesn't guarantee any specific value for tellg
, only that if seekg
is run sometime afterwards on its output, it will put the stream into the same place that it was. In any case, the output of tellg
is implementation-defined. It doesn't even have to be convertible to an integral type. In terms of implementations, generally files opened in binary mode (and in text mode for *nix systems) will produce tellg
output equal to the byte offset from the beginning of the file, while in text mode (non-*nix systems) producing some value greater or equal to the byte offset.
For a specific reason why tellg
was increasing by 1 each time you added a line, one possible factor that may have influenced this implementation-defined behaviour in your compiler might be the fact that the Windows line terminator \n\r
is two bytes instead of one. Of course, relying on implementation-defined behaviour is generally a bad idea.
Source: https://stackoverflow.com/a/22986486