二进制方法读写文件 参考自孙鑫视频13集

来源:互联网 发布:淘宝怎么修改密码 编辑:程序博客网 时间:2024/06/06 01:04

写文件:

    CFile file(L"1.txt",CFile::modeCreate | CFile::modeWrite);
    CArchive ar(&file,CArchive::store);
    int i = 0;
    float f = 1.3f;
    char c = 'a';
    CString str = L"TEST";

    ar<<i<<f<<c<<str;  //插入 将数据保存到文件中




读文件:

   CFile file(L"1.txt",CFile::modeRead);
    CArchive ar(&file,CArchive::load);
    int i;
    float f;
    char c;
    CString str;
    ar>>i>>f>>c>>str; //提取的顺序与保存的顺序要一致

    CString strResult;
    strResult.Format(L"%d,%f,%c,%s",i,f,c,str);
    AfxMessageBox(strResult);

0 0