Fstream's tellg / seekg returning higher value than expected. Help is appreciated

Posted by Cosmin on Stack Overflow See other posts from Stack Overflow or by Cosmin
Published on 2010-04-14T23:00:44Z Indexed on 2010/04/14 23:03 UTC
Read the original article Hit count: 181

Filed under:

Why does this fail, it's supposed to be simple and work ?

fisier.seekg(0, ios::end);
long lungime = fisier.tellg();

This returns a larger value than that of the file resulting in a wrong

char *continut = new char[lungime];

Any idea what the problem could be ?

I also tried counting to the end of the file one char at a time, that rendered the same result, a higher number than expected. But upon using getline() to read one line at a time, it works, there are no extra spaces...

Thank you

© Stack Overflow or respective owner

Related posts about c++