CArchive串行化操作

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CArchive串行化操作相关的知识,希望对你有一定的参考价值。

串行化保存数据

	//创建文件  
	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("[email protected]"));  
	//写入串行化  
	ar<<i<<ch<<f<<str;

串行化读出数据

//打开文件  
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);


以上是关于CArchive串行化操作的主要内容,如果未能解决你的问题,请参考以下文章