By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,930 Members | 1,246 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,930 IT Pros & Developers. It's quick & easy.

going back to the top line in input file

P: n/a
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?

Nov 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
ma******@gmail.com 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
Nov 22 '05 #2

P: n/a
John Ratliff wrote:
ma******@gmail.com 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().
Nov 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.