简体   繁体   English

长文件(15 MB)上的CStdioFile :: GetPosition错误几个字节

[英]CStdioFile::GetPosition on long file (15 MB) is wrong by few bytes

I have following code where the idea is to read a text file line by line and save the current position m_numBytesRead. 我有以下代码,其想法是逐行读取文本文件并保存当前位置m_numBytesRead。 So if I break the loop (on my case to split text parsing by chunks on big files) and I try to access a second time by making a Seek of m_numBytesRead-1, the ReadString is not geting the begin of the line as I expected. 因此,如果我中断了循环(就我的情况而言,是按大文件上的块拆分文本解析),然后尝试通过查找m_numBytesRead-1来进行第二次访问,则ReadString并没有按预期的那样开始。

CStdioFile fileLog;
if (fileLog.Open(m_strReadFileName, CFile::modeNoTruncate | CFile::modeRead | CFile::shareDenyNone))
{
    if (m_numBytesRead > 0)
        fileLog.CStdioFile::Seek(m_numBytesRead-1, CFile::begin);

    bool bBreakLoop = false;
    while (fileLog.ReadString(strLine) && !bBreakLoop)
    {

        // any condition to set bBreakLoop after few MB read...

        if (!bBreakLoop)
        {
            m_numBytesRead = fileLog.CStdioFile::GetPosition();
        }
    };
    fileLog.Close();
}

By debuging more in detail and comparing with the indexes I get on Notepad++, it seems that the CStdioFile::GetPosition() is not giving correct value, begining of new line to be read, but few bytes (12 on my case) more... 通过更详细地调试并与在Notepad ++上获得的索引进行比较,似乎CStdioFile :: GetPosition()给出的值不是正确的,要读取的新行开头,但更多的字节(在我的情况下为12)。 ..

Is is a bug on MFC or is there something I'm missing there ? 是MFC上的错误,还是我想念的东西? Does someone see similar issues ? 有人看到类似的问题吗?

Note that I'm using VS2010 on Windows 7. 请注意,我在Windows 7上使用VS2010。

Add open mode CFile::typeBinary to get byte-exact offsets. 添加打开模式CFile::typeBinary以获得字节精确的偏移量。 The default mode is text, which performs newline conversion which may mess up offsets. 默认模式是文本,它将执行换行符转换,这可能会使偏移量混乱。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM