going back in a text file.

I am opening a file
ifstream data ("data.txt");

and then reading some details from it.
while (getline(data, line, '\n'))
{
data_vec.push_back(line);
}

I would then like to go back to the start of the file so that I can read through it again.  
I am trying to use data.seekg(0, ios::beg) but when I run data.getline() it still only grabs the last entry in the file.  
How can I go back to the start of the file.  Do I need to close the file and then open it again?
KarlsAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
mnashadkaConnect With a Mentor Commented:
If you hit the end of the file, you need to call data.clear(); in order to clear the eof flag.  Then do data.seekg(0, ios::beg);
0
 
AxterCommented:
Try data.seekg(1, ios::beg)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.