Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fstream class pointer goes to -1

Status
Not open for further replies.

Arrowx7

Programmer
Feb 16, 2005
17
CA
I am sure people had this problem before and was wondering how people get around it. I use MyFile.ignore(100, '%') to get around the file where % is my marker (for example separating entries). In some cases when using this feature the pointer goes to -1, and I can't change it....in a way it gets 'jammed'. I know it's this because when I run:
Myfile.seekg(10); //puts pointer to 10 position
cout<<Myfile.tellg()<<endl;
Myfile.ignore(100, '%');
cout<<Myfile.tellg();

Output looks like this:
10
-1

when the pointer is at -1 I can't change it and the program gets messed up. Maybe it has something to do with .ignore function and loops? any suggestions? or is there an alternative to move around the file without using ignore?

Thanks in advance.
 
1. It's a stream position, not a class pointer.
2. If a stream is in failed state, tellg() returns an invalid stream position (-1). Ask a state with stream.fail() member function. Use stream.clear() if you correct the problem.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top