原始文件的结构是这样的:最前面是4个字节是存放第一段数据大小的,然后是第一段数据;接下来还是4个字节存放着第二段数据的大小,然后是第二段数据,依次有N段.
请问如何一段一段先读取大小数值,再读取相应的段数据内容.
请高手指点,
谢谢我本身是这样的:
CFile MyResultFile;
MyResultFile.Read(&decryptInputLength,sizeof(unsigned int)/sizeof(char));
resultStr = (char *)malloc(decryptInputLength);
MyResultFile.Read(resultStr,decryptInputLength);
这样可以读第一段,但是我不知道该如何读接下来的.
怎么使用循环读取呢?

解决方案 »

  1.   

    知道长度不就得了,API都在那里呢。
      

  2.   

    实在不确信的话你用CFile的Seek函数
    不过就你的问题不建议这么做,继续读就可以了
      

  3.   


          DWORD dwRead;      do
          {
             int len=0;
             dwRead = file.Read(&len, sizeof(int));
             if(dwRead <=0)break;
             char * buf=new char[len]
             dwRead = file.Read(buf,len);      }
          while (dwRead > 0);
      

  4.   

    刚我采用了:
                    while(haveReadLength < len2)
    {
    char *resultStr;
    int decryptLength = 0;
    MyResultFile.Read(&decryptLength,sizeof(unsigned int)/sizeof(char));
    resultStr = (char *)malloc(decryptLength);
    MyResultFile.Read(resultStr,decryptLength);
    decryptInputStr += resultStr;
    haveReadLength += decryptLength+4;
    decryptInputLength += decryptLength;
    }我以为有API可以简单的操作....