CFile file("D:\\1.txt",CFile::modeCreate | CFile::modeWrite);
 CArchive ar(&file,CArchive::store);
 int i=4;
 char ch='a';
 float f=1.3f;
 CString str("hello everyone");
 ar<<i<<ch<<f<<str;//序列化顺序写入到1.txt
类似于:cout<<i<<ch<<f<<str输出到显示设备
同理读取:
CFile file("D:\\1.txt", CFile::modeRead); // 模式改成read
 CArchive ar(&file,CArchive::load); // store 改成 load
 int i;
 char ch;
 float f;
 CString str;
 ar>>i>>ch>>f>>str; // <<符号改成>>符号,这时ar的作用跟cin有点像。

相关文章:

  • 2022-12-23
  • 2021-11-02
  • 2022-12-23
  • 2022-03-04
  • 2021-06-10
  • 2021-09-20
  • 2021-08-29
  • 2021-09-07
猜你喜欢
  • 2022-03-03
  • 2021-09-20
  • 2022-12-23
  • 2021-12-01
  • 2022-12-23
  • 2022-02-05
相关资源
相似解决方案