我有一个代码,其中的CArchive是用来读写和文件。在我的调查中,我发现CArchive对象在从文件的不同部分读取数据时会改变其位置。例如,如果文件结构类似于有页眉,然后是主体,然后是页脚。现在,如果有人想要读取页脚,那么CArchive只能通过转到文件中的特定位置来读取页脚。这是通过这个来完成的。
COleStreamFile stream;
//Stream is pointed to footer location.
stream.OpenStream(m_pStg, "Footer", nOpenFlags, pError); // pStg is LPSTORAGE
CArchive ar(&stream, CArchive::load);现在,我感兴趣的是CArchive将在哪个位置读取或写入。字节索引,文件位置或类似的东西。
发布于 2013-05-28 19:58:54
您不能直接从流对象获取位置,但可以从底层的CArchive - COleStreamFile获取位置。只需调用CFile::GetPosition即可。
示例:
COleStreamFile stream;
//Stream is pointed to footer location.
stream.OpenStream(m_pStg, "Footer", nOpenFlags, pError); // pStg is LPSTORAGE
CArchive ar(&stream, CArchive::load);
// Add some data.
ar << someData;
// And get the current position.
int currentPos = stream.GetPosition();https://stackoverflow.com/questions/16790732
复制相似问题