fopen的返回没有确切的信息,也没有异常的返回。
MFC的CFile家族就可以。

解决方案 »

  1.   

    Example/* FOPEN.C: This program opens files named "data"
     * and "data2".It  uses fclose to close "data" and
     * _fcloseall to close all remaining files.
     */#include <stdio.h>FILE *stream, *stream2;void main( void )
    {
       int numclosed;   /* Open for read (will fail if file "data" does not exist) */
       if( (stream  = fopen( "data", "r" )) == NULL )
          printf( "The file 'data' was not opened\n" );
       else
          printf( "The file 'data' was opened\n" );   /* Open for write */
       if( (stream2 = fopen( "data2", "w+" )) == NULL )
          printf( "The file 'data2' was not opened\n" );
       else
          printf( "The file 'data2' was opened\n" );   /* Close stream */
       if( fclose( stream ) )
          printf( "The file 'data' was not closed\n" );   /* All other files are closed: */
       numclosed = _fcloseall( );
       printf( "Number of files closed by _fcloseall: %u\n", numclosed );
    }
    OutputThe file 'data' was opened
    The file 'data2' was opened
    Number of files closed by _fcloseall: 1
    看看msdn。
      

  2.   

    我知道,不过我们都用SDK,不用MFC,所以要请教啊。
      

  3.   

    如果特别讨厌MFC的话,用OpenFile也可以,GetLastError得到错误代码,用FormatMessage得到错误信息
      

  4.   

    OpenFile还不够你用啊????
    真是无法理解你的点在什么地方
      

  5.   

    打开失败,可能不知,但读错误之类的可以用int ferror( FILE *stream );
      

  6.   

    HFILE _lopen(
      LPCSTR lpPathName,  // pointer to name of file to open
      int iReadWrite      // file access mode
    );
    GetLastError();
      

  7.   

    _lopen也是用于16位系统的,看来只好用CreateFile。
      

  8.   

    哈哈……不用CreateFile也可以的,我发现fopen其实内部调用了CreateFile,所以fopen失败也可以用GetLastError察看错误代码的!