CFile f;
CString cfileinfo,cfilename;
f.Open(cpath,CFile::modeRead);
int ifilelength;
ifilelength=f.GetLength(); for(int i=0; i<ifilelength;i++)
{
f.Read(buf,1);
cstr+=(CString)buf;
}
                   m_editFile.SetWindowText(cstr);我是想从文本文件读出内容加入EDIT控件里,这样是可以读出来可是在EDIT显示的时候却是乱码?
不知道是为什么,是不是我的系统的问题,我是用英文系统,还有一个问题就是
CFile 跟FILE 有什么区别吗??? 谢谢

解决方案 »

  1.   

    你的文本文件如果保存为非ANSI码就可能出错。
      

  2.   

    CStdioFile file;
    if(!file.Open("d:\\aa.txt", CFile::modeRead))
    {
    AfxMessageBox("can not open file!");
    return;
    }
    CString strLine,str="";

    while(file.ReadString(strLine))
    {
    str += strLine;
    }
    file.Close();
    GetDlgItem(IDC_EDIT1)->SetWindowText(str);或
    CFile cfile;
    char pbuf[100];
    cfile.Open("d:\\aa.txt",CFile::modeRead);
    UINT nBytesRead = cfile.Read( pbuf, 100 );
    GetDlgItem(IDC_EDIT1)->SetWindowText(pbuf);
      

  3.   

    谢谢 楼上的朋友现在可以了接分吧,还有一个就是可不可以再解释一个CFile 和FILE有什么区别吗??
      

  4.   

    FILE structure :Stores information about current state of stream; used in all stream I/O operations. (STDIO.H)
    =============================================================
    class CFile : public CObjectCFile is the base class for Microsoft Foundation file classes. It directly provides unbuffered, binary disk input/output services, and it indirectly supports text files and memory files through its derived classes. CFile works in conjunction with the CArchive class to support serialization of Microsoft Foundation Class objects.