16,471
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
#include <afxwin.h>
#include <stdio.h>
// 存储
void Store()
{
CFile file;
file.Open("C:\\serial.dat", CFile :: modeCreate
| CFile :: modeWrite);
CString strText = "hello CArchive";
CArchive ar(&file, CArchive :: store);
ar << 100 << 12.25 << strText;
ar.Close();
file.Close();
}
// 加载
void Load()
{
CFile file;
file.Open("C:\\serial.dat", CFile :: modeCreate
| CFile :: modeRead);
CArchive ar(&file, CArchive :: load);
int nValue = 0;
double dValue = 0;
CString strText;
ar >> nValue >> dValue >> strText;
printf("nValue = %d\ndValue = %dszBuff = %s\n",dValue, dValue, strText);
ar.Close();
file.Close();
}
int main(int argc, char* argv[])
{
Store();
Load();
getchar();
return 0;
}