mfc文本显示末尾乱码问题

来源:百度知道 编辑:UC知道 时间:2024/06/04 06:47:20
我在用MFC的richedit显示txt文档的时候,有的时候在末尾会出现乱码,有没有高手这是什么引起的啊?应该怎么解决啊?
CFile myFile;
if (!myFile.Open("1.txt",CFile::modeRead))
{
m_edit_strLog="此文件不存在";
GetDlgItem(IDC_RICHEDIT1)->SetWindowText(m_edit_strLog);
myFile.Close();
}
else
{
myFile.SeekToBegin();
int nLength=myFile.GetLength();
char *str= new char[nLength];
myFile.ReadHuge(str,nLength);
m_edit_strLog="";
m_edit_strLog+=str;
myFile.Close();
GetDlgItem(IDC_RICHEDIT1)->SetWindowText(m_edit_strLog);

char *str= new char[nLength + 1];
myFile.ReadHuge(str,nLength);
str[nLength] = 0;
就可以了 你的问题是没有找到结束符而已

没用过这么一个控件,不过,我觉得是你的数组长度的问题,试试
char *str=new char[nLength+1];
不行的话试试myFile.ReadHuge(str,nLength); 这个函数的nLength改为nLength+1(1不行换大点试试)。
希望能给你帮助