我用CFile读文本文件,全部读到一个CString里面,输出CString末尾总有乱码,是什么原因?
CFileDialog dlg(true,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"文本文件(*.txt)|*.txt|所有文件(*.*)|*.*||");
char *pBuf ;
CFile file;
CString str;if(dlg.DoModal()==IDOK)
{
pBuf = new char[file.GetLength()];
file.Read(pBuf, file.GetLength());
str=pBuf;
delete[] pBuf;
file.Close();
AfxMessageBox(str);
}输出的str末尾总有乱码。
CFileDialog dlg(true,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"文本文件(*.txt)|*.txt|所有文件(*.*)|*.*||");
char *pBuf ;
CFile file;
CString str;if(dlg.DoModal()==IDOK)
{
pBuf = new char[file.GetLength()];
file.Read(pBuf, file.GetLength());
str=pBuf;
delete[] pBuf;
file.Close();
AfxMessageBox(str);
}输出的str末尾总有乱码。
memset(pBuf,0,file.GetLength()+1);
AfxMessageBox(str);对话框可以弹出,只是最后有乱码,“茸茸茸茸茸茸茸”
http://www.wxxf.net/upload/file/alert/81964935040937f241f97362dae91ef1_error1.jpg
按下Ignore后的:
http://www.wxxf.net/upload/file/alert/81964935040937f241f97362dae91ef1_error2.jpg刚刚开始学windows的编程,有的地方不是很明白。我想问下是不是CFile file;的问题,它的值是什么?在if语句中它是直接被使用了。
楼上的几位能不能解释一下?真的很不明白啊!!
--------------------------------
zzol () :请回个短信或是邮件,可以的话能不能把你的正确的工程发给我,谢谢了。[email protected]