So i\'ve read all the lines from a file thusly
while (getline(ifile,line))
{
// logic
}
Where ifile is an ifstream and line
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.clear
– then try seeking:
ifile.clear();
ifile.seekg(0);
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
otherwise the next getline operation failed (MSVC v120)