Home

ostream

ostream is the standard output stream class in the C++ standard library. It is defined as part of the iostream facilities and represents the destination for character output. In standard terminology, std::ostream is an alias for std::basic_ostream<char>, with std::wostream serving as the wide-character counterpart. The class participates in the iostream hierarchy and uses a stream buffer (std::streambuf) to perform the actual I/O operations.

The primary interface of ostream is the insertion operators, commonly written as operator<<. These operators are

An ostream maintains formatting state that affects how data is written. This includes format flags, field width,

Common instances include std::cout for standard output, std::cerr for unbuffered error output, and std::clog for buffered

overloaded
to
handle
a
variety
of
built-in
types,
as
well
as
many
library
types,
and
can
be
extended
by
user-defined
types
through
appropriate
overloads.
The
operator<<
calls
return
a
reference
to
the
stream,
enabling
chaining
of
output
expressions,
such
as
std::cout
<<
"Value:
"
<<
x
<<
'\n'.
precision,
and
the
fill
character.
Manipulators,
many
defined
in
<iomanip>
(for
example
std::setw,
std::setprecision)
or
standard
ones
like
std::endl
and
std::flush,
modify
this
state
and
influence
subsequent
output
operations.
The
state
can
be
queried
and
modified,
and
the
stream
can
be
checked
for
errors
using
good(),
fail(),
and
related
member
functions.
logging.
The
standard
library
also
provides
derived
stream
classes
such
as
std::ostringstream,
std::istringstream,
and
std::ofstream,
which
extend
ostream
for
string-based
or
file-based
I/O.
User
code
can
extend
ostream
by
overloading
operator<<
for
custom
types
to
customize
how
objects
are
rendered
to
streams.