您当前的位置: 首页 >  令狐掌门 ar

MFC CArchive类读写文件的应用

令狐掌门 发布时间:2020-06-14 15:55:34 ,浏览量:2

 一 写文件

     CFile和CArchive进行绑定,CArchive把数据写到文件中,代码如下:

        CFile file;
	BOOL isOk = file.Open(L"1.txt", CFile::modeCreate | CFile::modeWrite);
	if (!isOk)
	{
		return;
	}

	CArchive ar(&file, CArchive::store);

	int a = 10;
	CString str = L"Hello MFC";
	TCHAR ch = 'a';

	ar > str >> ch;

	CString msg;
	msg.Format(L"a = %d, str = %s, ch = %c", a, str, ch);

	AfxMessageBox(msg);

	ar.Close();
	file.Close();

    测试结果

关注
打赏
1688896170
查看更多评论

令狐掌门

暂无认证

  • 2浏览

    0关注

    485博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.2714s