主题:CFile读取一个文本文件,并把内容显示到编辑控件中
CFile读取一个文本文件,并把内容显示到编辑控件中,怎么办
书上的是:
CFile file;
CString FileName="data.txt";
char buf[1000];//读1K
memset(buf,0,1000);//初始化内存,防止读出字符末尾出现乱码
if(!file.Open(FileName,CFile::modeRead))
{
MessageBox("没有文件!");
return;
}
file.Read(buf,sizeof(buf));
file.Close();
m_data=buf;//给文本框赋值CString m_data
UpdateData(false);//在文本框显示
MessageBox("读出成功!");
不太明白,有没有能简化点的
书上的是:
CFile file;
CString FileName="data.txt";
char buf[1000];//读1K
memset(buf,0,1000);//初始化内存,防止读出字符末尾出现乱码
if(!file.Open(FileName,CFile::modeRead))
{
MessageBox("没有文件!");
return;
}
file.Read(buf,sizeof(buf));
file.Close();
m_data=buf;//给文本框赋值CString m_data
UpdateData(false);//在文本框显示
MessageBox("读出成功!");
不太明白,有没有能简化点的