Open a file
void open( const char *_Filename,
ios_base::openmode _Mode = ios_base::in | ios_base::out,
int _Prot = (int)ios_base::_Openprot);
void open( const char *_Filename,
ios_base::openmode _Mode );
void open( const wchar_t *_Filename,
ios_base::openmode _Mode = ios_base::in | ios_base::out,
int _Prot = (int)ios_base::_Openprot);
void open( const wchar_t *_Filename, ios_base::openmode _Mode );
Parameters
_Filename
The name of the file to open.
_Mode
One of the enumerations in ios_base::openmode.
_Prot
The default file opening protection.
_Mode
An 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 The file is opened for input. The original file (if it exists) will not be truncated.
ios::out The file is opened for output.
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).
Note
that there is no ios::in or ios::out default mode for fstream objects.
You must specify both modes if your fstream object must both read and
write files.
_Prot
The file protection specification; defaults to the static integer filebuf::openprot, which is equivalent to the operating system default, filebuf::sh_compat, under MS-DOS. The possible nProt values are as follows:
filebuf::sh_compat Compatibility share mode (MS-DOS only).
filebuf::sh_none Exclusive mode — no sharing.
filebuf::sh_read Read sharing allowed.
filebuf::sh_write Write sharing allowed.
The filebuf::sh_read and filebuf::sh_write modes can be combined with the logical OR ( || ) operator.