Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
–
Return value:
The current position in the stream. If either the stream buffer
associated to the stream does not support the operation, or if it
fails, the function returns -1.
So
tellg
is "failing". A common reason is if you hit the end of the stream (a file here). This makes sense since you iterate until the end of the stream just before.
tellg
is returning -1 because it has encountered an error while reading the obj!! As
while
loop exits once the file has reached its end (no more data to read) and so obj is null and hence
tellg
return -1.
Refer to this site for more information-
http://www.cplusplus.com/reference/istream/istream/tellg/
Thanks for contributing an answer to Stack Overflow!
-
Please be sure to
answer the question
. Provide details and share your research!
But
avoid
…
-
Asking for help, clarification, or responding to other answers.
-
Making statements based on opinion; back them up with references or personal experience.
To learn more, see our
tips on writing great answers
.