void CMainFrame::OnArchiveWrite()
{
// TODO: 在此添加命令处理程序代码
CFile file;
BOOL isOk = file.Open(TEXT("../a.txt"), CFile::modeCreate | CFile::modeWrite);
if (FALSE == isOk)
{
return;
}
CArchive ar(&file, CArchive::store);
int a = 10;
CString str = TEXT("ABC");
TCHAR ch = 'A';
ar << a << str << ch;
ar.Close();
file.Close();
}
void CMainFrame::OnArchiveRead()
{
CFile file;
BOOL isOk = file.Open(TEXT("../a.txt"), CFile::modeRead);
if (FALSE == isOk)
{
return;
}
CArchive ar(&file, CArchive::load);
int a;
CString str;
TCHAR ch;
ar >> a >> str >> ch;
CString s;
s.Format(TEXT("%d %s %c"), a, str, ch);
MessageBox(s);
ar.Close();
file.Close();
}
网友评论