Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > going back to the top line in input file

Reply
Thread Tools

going back to the top line in input file

 
 
mahurshi@gmail.com
Guest
Posts: n/a
 
      11-12-2005
i am reading a file like this

ifstream infile(somefilenamestring.c_str())

while (infile >> myvariable)
{
/* do some interesting stuff */
}

now... if i want to get back to the first line of the file after i
executed this loop, what should i do ? is there a special thing that
needs to be done?

 
Reply With Quote
 
 
 
 
John Ratliff
Guest
Posts: n/a
 
      11-12-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> i am reading a file like this
>
> ifstream infile(somefilenamestring.c_str())
>
> while (infile >> myvariable)
> {
> /* do some interesting stuff */
> }
>
> now... if i want to get back to the first line of the file after i
> executed this loop, what should i do ? is there a special thing that
> needs to be done?
>


You could use seekg.

--John Ratliff
 
Reply With Quote
 
 
 
 
red floyd
Guest
Posts: n/a
 
      11-12-2005
John Ratliff wrote:
> (E-Mail Removed) wrote:
>
>> i am reading a file like this
>>
>> ifstream infile(somefilenamestring.c_str())
>>
>> while (infile >> myvariable)
>> {
>> /* do some interesting stuff */
>> }
>>
>> now... if i want to get back to the first line of the file after i
>> executed this loop, what should i do ? is there a special thing that
>> needs to be done?
>>

>
> You could use seekg.


Don't forget to call clear() before seekg().
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Read a file line by line and write each line to a file based on the5th byte scad C++ 23 05-17-2009 06:11 PM
Going back to the top of the page Adrian HTML 29 01-11-2009 09:54 AM
Firefighters at the site of WTC7 "Move away the building is going to blow up, get back the building is going to blow up." Midex Python 24 05-07-2007 04:23 AM
Stop page going back to the top when submitting Mike Owen ASP .Net Web Controls 8 11-09-2005 01:40 AM
Grabbing a string and going through it line by line Maziar Aflatoun ASP .Net 1 07-05-2005 04:44 PM



Advertisments