void CTestProgramDlg::WriteTxT()
{
CString filename("四元式.txt");
CStdioFile myFile;
CFileException fileException;
if(myFile.Open(filename,CFile::typeText|CFile::modeCreate|CFile::modeReadWrite),&fileException)
{
CString str1;
m_edit2.GetWindowText(str1);
myFile.WriteString(str1);
}
else
{
TRACE("Can't open file %s,error=%u\n",filename,fileException.m_cause);
}
myFile.Close();
}
是这个出问题么?
因为VS版本不一致,我没法打开你的工程进行调试,只能分析一下。
这里获取和写入本身是没有什么问题的,如果缺少内容,应该是edit2里面有特殊结束标记或者特殊字符造成的流文件无法一次写入全部内容。
建议解决办法:
设置断点,调试str1获取是否完整。也可以在WriteString之前,AfxMessageBox弹出看看str1内容。
使用CFile::Write方法保存文件试试。
也可能是typeText造成的不可打印字符问题,但这个可能不是很大。