我试图在 ifstream 上使用下面的代码两次 - 在我从文件中读取任何内容之前,以及在我读到它的末尾之后(使用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
是文件中间的一些位置。对于这个问题并不重要。)
在第一次运行时,代码按预期工作。然后当我第二次运行它时,变量的值test1
是-1,即使在使用clear()
.
我查看了类似的问题,并且所有解决方案都说使用功能clear()
(我已经这样做了)。