returning to the beginning of fstream

I have an issue going back to the beginning of the fstream I have opened.
I use my first pass over the file to count the lines in the file, so that I could create the dynamic array size, then I use this code below to return to the beginning of the file. And it works mostly, but it doesn't work when I have the last line, as an empty line. If the last line of the inputFile is empty, it then returns all empty lines in my array.. I have a feeling the problem is in seeking the beginning of the file, because it works when I close the file, then reopen, but I think that may be a wasted and unclean way to do this.. Anyone know how to get past this?

inputFile.seekg(0, ios::beg);
When you finish reading all the contents of your file, the state of the stream would be eof, thus all subsequent input operations will fail.
To clear the state back to good call inputFile.clear()
http://www.cplusplus.com/reference/iostream/ios/clear/
Hi Bazzy,

the call didn't work when alone, but when used together.. it worked! Thanks so much for your input!!

1
2
inputFile.clear();
inputFile.seekg(0, ios::beg);
Topic archived. No new replies allowed.