小哈龙 沙滩

版权声明:需要转载的请注明出处 https://blog.csdn.net/qq_22642239/article/details/77374861
使用MFC将字符串的内容保存到指定目录下的文档中

void CIDCard_readDlg::OnBnClickedButton2()
{
// TODO: 在此添加控件通知处理程序代码
CString str = “测试成功”;
MessageBox(“测试完成,请将测试成功结果保存,然后准备测试下一个模块,”);
CFileDialog dlg(FALSE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
“All Files(.TXT)|.TXT||”, AfxGetMainWnd());
CString strPath;

if (dlg.DoModal() == IDOK)
{
strPath = dlg.GetPathName() + “.txt”;
CFile file(_T(strPath), CFile::modeCreate | CFile::modeWrite);

file.Write(str, str.GetLength());
file.Close();
}
}