我的文件很大,但是,结果buf中只有最初的几个字符。我怀疑是中间读到了空字符,这样
的问题应该怎么处理? 
CFile Pfile
if( ! Pfile.Open("d:\\download\\ccc.dat",CFile::modeRead | CFile::typeBinary))
{
    AfxMessageBox("File open fail...");
    return false;
};
byte buf[4096];
int count;
CString s;
do
{
    count = Pfile.Read(buf,4096);
    if( count == 4096)
    s += buf;
} while (count == 4096);
...

解决方案 »

  1.   

    注意, 没有我现在注释掉的内容 
    do
    {
        count = Pfile.Read(buf,4096);
    //  if( count == 4096)     
        s += buf;
    } while (count == 4096);
      

  2.   

    不要用CString存储二进制数据,
    CString不能存储'\0'
    实际读到的数据字节数应该是 count
      

  3.   

    十分感谢楼上的, 但我还有疑问。
        是这样, 我要把这个读入的buf 串行化处理, 发送出去,
    所以, 就将它读到了CString 中了。   如果CString 不能处理
    '\0' ,Serialize 化的处理(多数用法都是针对CString 的)就
    没法处理了普通的二进制文件传送了。