本人初学VC,遇到点小难题,望高手指教!
问题是:
我在Dialog类中修改变量,怎样把此变量保存到文件中去,并怎样在下一次执行程序时从文件中调出此变量!

解决方案 »

  1.   

    fingerfox(狐狸.兄弟会)说的不错
      

  2.   

    比如要把一个CString型的变量nVariable保存到文件中去,可以这样!
    保存:theFile.Open("D:\\amd.asd",CFile::modeCreate|CFile::modeWrite);
    CArchive ar(&theFile,CArchive::store);
    ar<<nVariable;
    ar.close();
    theFile.close();
    从文件中调出变量
    theFile.Open("D:\\amd.asd",CFile::modeRead);
    CArchive ar(&theFile,CArchive::load);
    ar>>nVariable;
    ar.close();
    theFile.close();
      

  3.   

    不好意思,刚才少写了一句!
    比如要把一个CString型的变量nVariable保存到文件中去,可以这样!
    保存:
    CFile theFile;
    theFile.Open("D:\\amd.asd",CFile::modeCreate|CFile::modeWrite);
    CArchive ar(&theFile,CArchive::store);
    ar<<nVariable;
    ar.close();
    theFile.close();
    从文件中调出变量:
    CFile theFile;
    theFile.Open("D:\\amd.asd",CFile::modeRead);
    CArchive ar(&theFile,CArchive::load);
    ar>>nVariable;
    ar.close();
    theFile.close();
    好了,你试试吧!不知道能不能帮你的忙!