ofstream::open
void open ( const char * filename, openmode mode = out | trunc );
ofstream
  cplusplus.com  

Open a file.
  Opens a file. The stream's file buffer is associated with the specified file to perform the i/o operations.

Parameters.

filename
String containing the name of the file to be opened.
mode
Flags describing the requested i/o mode for the file. This is an object of type ios_base::openmode, it generally consist of a combination of the following flags (member constants):
biteffect
app(append) Seek to the end of the stream before each output operation.
ate(at end) Seek to the end of the stream when opening.
binaryConsider stream as binary rather than text.
inAllow input operations on a stream.
outAllow output operations on a stream.
trunc(truncate) Truncate file to zero when opening.

Return Value.
  none

Example.

// ofstream::open
#include <fstream>
using namespace std;

int main () {

  ofstream outfile;

  outfile.open ("test.txt", ofstream::out | ofstream::app);
  outfile << "This sentence is appended to the file content\n";
  outfile.close();

  return 0;
}
This example opens a file and appends a sentence to its content.

Basic template member declaration ( basic_ofstream<charT,traits> ):
void open ( const char * filename, openmode mode = out | trunc );

See also.
  close
  ofstream class


© The C++ Resources Network, 2001