• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 182
  • Last Modified:

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?
0
Karls
Asked:
Karls
1 Solution
 
AxterCommented:
Try data.seekg(1, ios::beg)
0
 
mnashadkaCommented:
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
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.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now