Returning to beginning of file after getline

This is because the eof flag has been set on the stream - due to you reaching the end of the file. so you have to clear this as an additional step.

Eg

ifile.clear();
ifile.seekg (0, ios::beg);

FYI: In my case, the order DID matter, thus

  1. clear
  2. seek

otherwise the next getline operation failed (MSVC v120)


Since you have reached (and attempted to read past) the end of the file, the eof and fail flags will be set. You need to clear them using ifile.clearthen try seeking:

ifile.clear();
ifile.seekg(0);

Tags:

C++