一 写文件
CFile和CArchive进行绑定,CArchive把数据写到文件中,代码如下:
CFile file;
BOOL isOk = file.Open(L"1.txt", CFile::modeCreate | CFile::modeWrite);
if (!isOk)
{
return;
}
CArchive ar(&file, CArchive::store);
int a = 10;
CString str = L"Hello MFC";
TCHAR ch = 'a';
ar > str >> ch;
CString msg;
msg.Format(L"a = %d, str = %s, ch = %c", a, str, ch);
AfxMessageBox(msg);
ar.Close();
file.Close();
测试结果