basic_ofstream Constructors

To create a file stream object for output.

  basic_ofstream();

  explicit basic_ofstream

  (const char *s, ios_base::openmode mode = ios_base::out |   ios_base::trunc);  
Remarks

The class basic_ ofstream creates an object for handling file output. It may be opened later using the ofstream:: open() member function. It may also be associated with a file when the object is declared. The default open mode is ios::out.

There are only certain valid file opening modes for an ofstream object. See basic_ofstream::open for a list of valid opening modes.

Listing: Example of basic_ofstream::ofstream() usage:
// Before the operation the file ewl-test 
// may or may not exist.

#include <iostream>
#include <fstream> 
#include <cstdlib> 

char outFile[] = "ewl-test";

int main()
{
using namespace std;
   ofstream out(outFile);

   if(!out.is_open()) 
      {cout << "file not opened"; exit(1);}

   out << "This is an annotated reference that " 
      << "contains a description\n" 
      << "of the Working ANSI C++ Standard "
      << "Library and other\nfacilities of "
      << "the Embedded Warrior Library. ";

   out.close();
   return 0;   
}

Result:

This is an annotated reference that contains a description of the Working ANSI C++ Standard Library and other facilities of the Embedded Warrior Library.