在VC++中,如何判断一个文本文件的大小?,请帮忙!不胜感谢!

解决方案 »

  1.   

    CFile myFile;
    myFile("c:\\yout.txt",CFile::modeRead);
    DWORD fileSize = myFile.GetLength( ) ;
    myFile.Close();
      

  2.   

    用GetLength()如下例:
    CFile* pFile = NULL;
       TRY
       {
          pFile = new CFile(_T("C:\\WINDOWS\\SYSTEM.INI"),
             CFile::modeRead | CFile::shareDenyNone);
          ULONGLONG dwLength = pFile->GetLength();
          CString str;
          str.Format(_T("Your SYSTEM.INI file is %I64u bytes long."), dwLength);
          AfxMessageBox(str);
       }
       CATCH(CFileException, pEx)
       {
          pEx->ReportError();
       }
       AND_CATCH(CMemoryException, pEx)
       {
          AfxAbort();
       }
       END_CATCH
       if (pFile != NULL)   
       {
          pFile->Close();
          delete pFile;
       }