計(jì)算機(jī)二級(jí)考試C語(yǔ)言輔導(dǎo):剖析VC中的文件操作3

字號(hào):

vc中的文件操作
    File Operations in VC
    1:Find the file
    CString strFileName;
    CFileFind finder;
    BOOL bWorking=finder.FindFile(”c:\windows\*.cab”);
    if(bWorking)
    {
    bWorking=finder.FindNextFile();
    strFileName=finder.GetFileName();//or finder.GetFileTitle();
    }
    2:Open or Save file
    CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT,”All Files(*.*)|*.*||”
    ,AfxGetMainWnd());
    3:Read and Write File
    //Read File
    char cRead[10]; CFile mFile(_T(”test.txt”),CFile::modeRead);
    if(mFile.GetLength()<2)
    return ;
    mFile.Read(cRead,10);
    mFile.Close();
    //Write File:
    CFile mFile(_T(”test.txt”),CFile::modeWrite|CFile:modeCreate);