Create文件时有参数可以选择,看一看MSDN吧。

解决方案 »

  1.   

    ifstream 打开时创建有什么用?
    ofstream( const char* szName, int nMode = ios::out, int nProt = filebuf::openprot );
    nModeAn integer that contains mode bits defined as ios enumerators that can be combined with the bitwise OR ( | ) operator. The nMode parameter must have one of the following values: ios::app   The function performs a seek to the end of file. When new bytes are written to the file, they are always appended to the end, even if the position is moved with the ostream::seekp function.
    ios::ate   The function performs a seek to the end of file. When the first new byte is written to the file, it is appended to the end, but when subsequent bytes are written, they are written to the current position.
    ios::in   If this mode is specified, then the original file (if it exists) will not be truncated.
    ios::out   The file is opened for output (implied for all ofstream objects).
    ios::trunc   If the file already exists, its contents are discarded. This mode is implied if ios::out is specified and ios::ate, ios::app, and ios:in are not specified.
    ios::nocreate   If the file does not already exist, the function fails.
    ios::noreplace   If the file already exists, the function fails.
    ios::binary   Opens the file in binary mode (the default is text mode
      

  2.   

    ios_base::openmode
    typedef T3 openmode;
    static const openmode app, ate, binary, in, out, trunc;
    The type is an enumerated type T3 that describes an object that can store the opening mode for several iostreams objects. The distinct flag values are:app, to seek to the end of a stream before each insertion 
    ate, to seek to the end of a stream when its controlling object is first created 
    binary, to read a file as a binary stream, rather than as a text stream 
    in, to permit extraction from a stream 
    out, to permit insertion to a stream 
    trunc, to truncate an existing file when its controlling object is first created 
      

  3.   

    使用CFileFind类最为方便地查询文件是否存在,不存在则创建