?
Solved

End of file question...PLZ HELP

Posted on 2003-02-20
6
Medium Priority
?
178 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

764 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