?
Solved

End of file question...PLZ HELP

Posted on 2003-02-20
6
Medium Priority
?
179 Views
Last Modified: 2010-04-01
I am writting a program to open a file with a specific header and behave accordingly, based off of the header.  What I am running into is a problem once I reach the files end of file.  This seems to cause my program to act like it has forgotten about the file.  I have tried to use .seekg(0) to get it to go back to the beginning of the file and that has no effect.  I have tried to close the file and reopen it within my program, again has no effect.  The only way I could get the program to continue is if I make a copy of the origional file and once I have run my check against the origional file, which check various components of the file till it reaches the end of the file. After I have reached the origional files end of file, I have to do a .open on the copy of the origional to get my program to continue.  Anyone know of what may be causing this?

Thanks in advance.

Eifson
0
Comment
Question by:Eifson
  • 5
6 Comments
 

Author Comment

by:Eifson
ID: 7986330
Man I just read my post, forgive my errors.  It is 2:30 in the morning and I have been working on this thing for days.

Eifson

Happy programming and good luck.

Any help on this would be appreciated.
0
 
LVL 12

Accepted Solution

by:
Salte earned 500 total points
ID: 7986383
The problem is that seekg(0) does not reset the 'end of file' bit. So the stream thinks it is at end of file even if you seek to the beginning.

Try file.clear(); immediately after file.seekg(0); :-) It should do wonders!

Alf
0
 

Author Comment

by:Eifson
ID: 7986426
After I do that do I need to reopen the file?

Eifson
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 

Author Comment

by:Eifson
ID: 7986437
After I do that do I need to reopen the file?

Eifson
0
 

Author Comment

by:Eifson
ID: 7986549
Dear Alf,

One word for you!  PIMP

Thank you very much!  Like you said it worked wonders for me.  Thank god I can sleep now.  I really appreciate your quick and helpful response.  You are the MAN!!!

Eifson

Good luck and happy programming!

Giving you a few more points in appreciation.  Thanks again.
0
 

Author Comment

by:Eifson
ID: 7986552
Thanks again!  See above post for my comment.

Eifson
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question