利用GetLastError函数,看看发生了什么错误
你的写法有误。
请参照以下代码:
CString strText = “”;
CString szLine = “”;
//打开文件
CStdioFile file;
file.Open("ts.txt",CFile::modeRead);
//逐行读取字符串
while( file.ReadString( szLine ) )
{
strText += szLine;
}
MessageBox(strText);
//关闭文件
file.Close();
您好,感谢您的帮助,我这一块是Open函数出现了问题,没能打开txt文件,请问是什么原因?谢谢
CFile::Open() 调用了2次,另外文件最好是使用绝对路径~