ofstream();
ofstream( const char* szName, int nMode = ios::out, int nProt = filebuf::openprot );
ofstream( filedesc fd );
ofstream( filedesc fd, char* pch, intnLength);
Parameters
szName
The name of the file to be opened during construction.
nMode
An integer that contains mode bits defined as ios enumerators that can be combined with the bitwise OR (| ) operator. ThenMode parameter must have one of the following values:
nProt
The file protection specification; defaults to the static integerfilebuf::openprot that is equivalent tofilebuf::sh_compat. The possiblenProt values are:
To combine the filebuf::sh_read and filebuf::sh_write modes, use the logical OR (|| ) operator.
fd
A file descriptor as returned by a call to the run-time function_open or_sopen; filedesc is atypedef equivalent toint.
pch
Pointer to a previously allocated reserve area of length nLength. ANULL value (ornLength = 0) indicates that the stream will be unbuffered.
nLength
The length (in bytes) of the reserve area (0 = unbuffered).
Remarks
The four ofstream constructors are:
Constructor | Description |
ofstream() | Constructs an ofstream object without opening a file. |
ofstream( const char*, int, int ) | Contructs an ofstream object, opening the specified file. |
ofstream( filedesc ) | Constructs an ofstream object that is attached to an open file. |
ofstream( filedesc, char*, int ) | Constructs an ofstream object that is associated with afilebuf object. Thefilebuf object is attached to an open file and to a specified reserve area. |
All ofstream constructors construct a filebuf object. The first three use an internally allocated reserve area, but the fourth uses a user-allocated area. The user-allocated area is not automatically released during destruction.
ofstream();
ofstream( const char* szName, int nMode = ios::out, int nProt = filebuf::openprot );
ofstream( filedesc fd );
ofstream( filedesc fd, char* pch, intnLength);
Parameters
szName
The name of the file to be opened during construction.
nMode
An integer that contains mode bits defined as ios enumerators that can be combined with the bitwise OR (| ) operator. ThenMode parameter must have one of the following values:
nProt
The file protection specification; defaults to the static integerfilebuf::openprot that is equivalent tofilebuf::sh_compat. The possiblenProt values are:
To combine the filebuf::sh_read and filebuf::sh_write modes, use the logical OR (|| ) operator.
fd
A file descriptor as returned by a call to the run-time function_open or_sopen; filedesc is atypedef equivalent toint.
pch
Pointer to a previously allocated reserve area of length nLength. ANULL value (ornLength = 0) indicates that the stream will be unbuffered.
nLength
The length (in bytes) of the reserve area (0 = unbuffered).
Remarks
The four ofstream constructors are:
Constructor | Description |
ofstream() | Constructs an ofstream object without opening a file. |
ofstream( const char*, int, int ) | Contructs an ofstream object, opening the specified file. |
ofstream( filedesc ) | Constructs an ofstream object that is attached to an open file. |
ofstream( filedesc, char*, int ) | Constructs an ofstream object that is associated with afilebuf object. Thefilebuf object is attached to an open file and to a specified reserve area. |
All ofstream constructors construct a filebuf object. The first three use an internally allocated reserve area, but the fourth uses a user-allocated area. The user-allocated area is not automatically released during destruction.