描述:
当调试到ReadString后直接崩溃
修改之前
CStdioFile PassKeyFile;
CString CMFCFile = GetAppPath().c_str();
CMFCFile = CMFCFile + "\\test.txt";
PassKeyFile.Open(CMFCFile, CFile::modeRead);
vector<CString>vectPassKey;
CString PassKey;
while (PassKeyFile.ReadString(PassKey))
{
vectPassKey.push_back(PassKey);
}
PassKeyFile.Close();
修改之后
CStdioFile PassKeyFile;
CString CMFCFile = GetAppPath().c_str();
CMFCFile = CMFCFile + "\\test.txt";
//需要判断是否打开成功
if (!PassKeyFile.Open(CMFCFile, CFile::modeRead))
{
AfxMessageBox("文件打开失败");
return false;
}
vector<CString>vectPassKey;
CString PassKey;
while (PassKeyFile.ReadString(PassKey))
{
vectPassKey.push_back(PassKey);
}
PassKeyFile.Close();
分析:
主要的原因是在release下没有test.txt这个文件,而且没有判断打开是否成功,造成PassKeyFile.ReadString(PassKey)不成功,直接断开调试