c++ifstreamseekg

seekg after reading to the end of the file


I'm trying to use the code below on the ifstream twice - before I read anything from the file, and after I read to the end of it (using readline()).

m_hexFile->m_ifsteam->seekg(0, m_hexFile->m_ifsteam->ios_base::end);
test1 = m_hexFile->m_ifsteam->tellg();
m_hexFile->m_ifsteam->clear();
m_hexFile->m_ifsteam->seekg(m_hexFile->m_startPosition);
test1 = m_hexFile->m_ifsteam->tellg();

(m_startPosition is some poisition in the middle of the file. It is not important for this issue.)

On the first run, the code works as expected. Then when I run it the second time, the value of the variable test1 is -1, even after using clear().

I looked through the similar questions, and all of the solutions said to use function clear() (which I already do).


Solution

  • Solution was to check elsewhere. I had closed the stream somewhere else in the program. Using the code above on a closed stream ofcourse wont work.