CArchive串行化操作
阿新 • • 發佈:2017-10-07
mfc 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串行化操作