为什么我把程序改成这样就不能用了啊?
CFile MyFile;
char* buf=new char[1];
MyFile.Open("test.txt",CFile::modeRead);
MyFile.Read((void*)&buf,1);//只读取3位
MyFile.Close();CString strOutput;
strOutput.Format("%d",atoi(buf));
pDC->TextOut(0,0,strOutput);test.txt文件内容如下:3
有人能帮我吗??
万分感谢。。祝帮助我的好人万事如意中秋快乐!

解决方案 »

  1.   

    把MyFile.Read((void*)&buf,1);//改为MyFile.Read((void*)buf,1);//
    输出结果依然错误。。求答案。。
      

  2.   

    改为:
    CFile MyFile;
    char* buf=new char[1];
    MyFile.Open("test.txt",CFile::modeRead);
    MyFile.Read((void*)&buf,1);//只读取3位
    MyFile.Close();//add//只读取3位(3字节?)
    buf[3]=0x00;CString strOutput;
    strOutput.Format("%d",atoi(buf));
    pDC->TextOut(0,0,strOutput);应该可以.
      

  3.   

    怀疑是不是文件打开失败,这样Read执行出错。
    CFile MyFile;
    char* buf=new char[1];
    if(MyFile.Open("test.txt",CFile::modeRead))
    {
    MyFile.Read((void*)&buf,1);//只读取3位
    MyFile.Close();
    }
      

  4.   

    改为MyFile.Read((void*)buf,1);
    是对的(而且必须是这样的)。
    看看是不是其他错误。
      

  5.   

    你把buf的空间申请成2,设置buf[1]=0你的程序中把buf当成字符串,字符串以0结尾