C的fread
CFile类的read都可以指定长度的

解决方案 »

  1.   

    定义一个unsighn char数组,把数据写入数组内。如果使用STL中的fstream,倒是可以设置,流读取时,读取0x00
    MFC中的CFile不是特别了解
      

  2.   

    void CTest10Dlg::OnButton3() 
    {
    CString strFileName = "f:\\1.txt" ;
    char szBuf[16] = {0} ;
    strcpy(szBuf,"ABCDE"); CFile file ;
    file.Open(strFileName,CFile::modeWrite|CFile::modeCreate);
    file.Write(szBuf,sizeof(szBuf)/sizeof(szBuf[0]));
    file.Close(); memset(szBuf,' ',sizeof(szBuf)/sizeof(szBuf[0])) ;
    file.Open(strFileName,CFile::modeRead );
    file.Read(szBuf,sizeof(szBuf)/sizeof(szBuf[0])) ;
    file.Close();
    }
      

  3.   

    一般都有返回读入字节数的,就是读了多少字节,根据那个处理
    实在不行可以用一个结构体
    struct abc{
    char mystring[512];
    int len;
    }
      

  4.   

    我将问题总结了一下,见
    http://www.vcshare.net/VC/VC_small_skill/VC_small_skill_79.htm
    http://www1.vcshare.net/VC/VC_small_skill/VC_small_skill_79.htm第一个链接是电信站,第二个链接是网通站
      

  5.   

    c++ 的 string 也可以