串行化保存数据
1
2
3
4
5
6
7
8
9
10
11
|
//创建文件
CFile file(_T(
"1.txt"
),CFile::modeCreate | CFile::modeWrite);
//串行化,存储
CArchive ar(&file,CArchive::store);
//存储数据
int
i = 0x31;
char
ch =
'A'
;
float
f = 1.3f;
CString str(_T(
"chinayu@qq.com"
));
//写入串行化
ar<<i<<ch<<f<<str;
|
串行化读出数据
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
//打开文件
CFile file(
"1.txt"
,CFile::modeRead);
//加载流
CArchive ar(&file,CArchive::load);
//接收变量
int
i;
char
ch;
float
f;
CString str;
CString strresult;
//提取数据给变量
ar>>i>>ch>>f>>str;
strresult.Format(
"%d,%c,%f,%s"
,i,ch,f,str);
//转化格式
AfxMessageBox(strresult);
|
本文转自Chinayu201451CTO博客,原文链接:http://blog.51cto.com/9233403/1970638 ,如需转载请自行联系原作者