//strTxt返回txt文件内容
void OnRead(CString &strTxt)
{
CString strFilter,fileName;
strFilter="Text Files(*.txt)|*.txt||";
CFileDialog dlg(TRUE, NULL, NULL, OFN_EXPLORER|OFN_HIDEREADONLY|OFN_ENABLESIZING|OFN_FILEMUSTEXIST,strFilter);
if(dlg.DoModal() == IDOK )//显示打开文件对话框
{
fileName=dlg.GetPathName();
CFile openfile(fileName,CFile::modeRead);//构造CFile对象
int length=openfile.GetLength();//获取文件长度
char *strText;
strText=new char[length];
openfile.Read(strText,length);
openfile.Close();//关闭文件
strTxt=(CString)strText;
delete [] strText;
}
}
//后续可以把读取txt文件一行给整理出来。。。
mfc读txt文件
最新推荐文章于 2023-11-18 02:12:03 发布