Get Line

I want to read certain lines from a file, let's say the 4th and the 1st lines. First I used getline (which I read from here: http://www.cplusplus.com/forum/beginner/15303/ ) 4 times to read the 4th line. Using getline again will give me the 5th line, not the 1st line. So how do I get the 1st line?
I think you can solve your problem by having look at cin.ignore();
Two ways:

Close and reopen the file. Then read again.
1
2
3
4
filein.close();
filein.open("mydata.txt");
if (filein.is_open())
   std::getline(filein, lineOne);


On the first read store into a different variable.
1
2
3
std::getline(filein, lineOne);
for (int i = 0; i < 3; ++i)
   std::getline(filein, lineFour);
Topic archived. No new replies allowed.