public member function
<ostream> <iostream>

std::ostream::ostream

initialization (1)
explicit ostream (streambuf* sb);
initialization (1)
explicit ostream (streambuf* sb);
copy (2)
ostream& (const ostream&) = delete;
move (3)
protected: ostream& (ostream&& x);
Construct object
Constructs an ostream object.

(1) inititalization constructor
Assigns initial values to the components of its base classes by calling the inherited member ios::init with sb as argument.
(2) copy constructor (deleted)
Deleted: no copy constructor.
(3) move constructor (protected)
Acquires the contents of x, except its associated stream buffer: It calls ios::move to transfer x's internal components inherited from ios. x is left with its associated stream buffer unchanged and not tied (all other components of x are in an unspecified but valid state after the call).

Parameters

sb
Pointer to a streambuf object.
x
Another ostream object.

Example

1
2
3
4
5
6
7
8
9
10
11
12
// ostream constructor
#include <iostream>     // std::cout, std::ostream, std::ios
#include <fstream>      // std::filebuf

int main () {
  std::filebuf fb;
  fb.open ("test.txt",std::ios::out);
  std::ostream os(&fb);
  os << "Test sentence\n";
  fb.close();
  return 0;
}

This code uses a filebuf object (derived from streambuf) to open the file test.txt. The buffer is then passed as parameter to the ostream constructor, associating it to the stream.

Objects of class ostream are seldom constructed directly. Generally some derived class is used (like the standard ofstream and ostringstream).

Data races

The object pointed by sb may be accessed and/or modified.

Exception safety

If an exception is thrown, the only side effects may come from accessing/modifying sb.

See also