I am reading in image files in a program and I read in
the header in ascii mode. The problem is, sometimes tellg
() gives me a completely incorrect result and sometimes
it is just fine. Here is an example:
char input[200];
std::ifstream fin("blocks.pgm", std::ios::in);
std::ifstream::pos_type position = fin.tellg();
fin>>input;
position = fin.tellg();
When I run this code, input gets the first two bytes of
the file as it should. The first few bytes of the file
are: 'P5 302 274 255 '. Now, even though it only read
two bytes into input, when tellg() is called on the next
line it returns a position of 3586 bytes into the file.
If I change the input file to "original.pgm", a different
image file, everything works fine. The first 15 bytes
are identical and after the first two bytes are read,
tellg() returns a position of 2 bytes into the file.
If I delete everything in blocks.pgm after the first 15
bytes it seems to work just fine. I don't understand how
bytes that should not be read could be affecting the tellg
() function.
Chris