用c#的System.IO.BinaryWriter.Write(string strText)写入一串数字,比如:8678788278868682到文件MyFile.vsk中(在c#中读取验证无误)然后在vc6.0中读取:
CStdioFile stdFile;
UINT uNumber = 0;
CString strTemp;
stdFile.Open("MyFile.vsk",CFile::modeRead|CFile::typeBinary)
stdFile.ReadString(strTemp);   
stdFile.Close();结果发现strTemp读出来的字符不可辨识。然后修改为
stdFile.Open("MyFile.vsk",CFile::modeRead|CFile::typeBinary)
if(strFile.Read(&uNumber,sizeof(uNumber))!=sizeof(uNumber))
{
   stdFile.Close();
   return;
}
stdFile.ReadString(strTemp);   
stdFile.Close();这时读出来的strTemp少了两个数字,成了:78788278868682。
请问这是什么原因,应该怎么解决?

解决方案 »

  1.   

    你写入的是二进制。CStdioFile处理的是字符文件。如果你强制用二进制打开,不如直接用CFile。读取的时候你只读取了一个UINT,长度不够。
      

  2.   

    谢谢,用CFile读写就对了,定义了一个字符指针
    char *buffer = new char[file.GetLength()];
    然后转换,不过数组头两个字符是干什么用的?
      

  3.   

    呵呵,我开头不是说了吗?文件是用c#写进去的,内容就只有我说的那个数字串,但是VC中读取到buffer中,但是buffer[0]是asc字符16,buffer[1]是asc码0,从buffer[2]开始才是当初写入的数字。不知这是什么原因呢?