An output stream object is a destination for bytes. The three most important output stream classes are
ostream class, through the derived class
basic_ostream, supports the predefined stream objects:
cerrstandard error with limited buffering
cerrbut with full buffering
Objects are rarely constructed from
ostream; predefined objects are generally used. In some cases, you can reassign predefined objects after program startup. The
ostream class, which can be configured for buffered or unbuffered operation, is best suited to sequential text-mode output. All functionality of the base class,
ios, is included in
ostream. If you construct an object of class
ostream, you must specify a
streambuf object to the constructor.
ofstream class supports disk file output. If you need an output-only disk, construct an object of class
ofstream. You can specify whether
ofstream objects accept binary or text-mode data when constructing the
ofstream object or when calling the
open member function of the object. Many formatting options and member functions apply to
ofstream objects, and all functionality of the base classes
ostream is included.
If you specify a filename in the constructor, that file is automatically opened when the object is constructed. Otherwise, you can use the
open member function after invoking the default constructor.
Like the run-time function
ostringstream class supports output to in-memory strings. To create a string in memory by using I/O stream formatting, construct an object of class
In This Section