Home

basicostream

basic_ostream is a class template in the C++ standard library that provides the interface for output streams. It forms the basis for character-output streams, coordinating writing to an underlying stream buffer and offering formatting controls and insertion operations used by higher-level stream classes.

Template parameters are charT, the character type (for example char or wchar_t), and Traits, the character traits

It supplies member functions for direct writing, such as put and write, and for controlling output positioning

std::ostream is a common instantiation of basic_ostream<char>, while std::wostream uses wchar_t. The template also underpins other

Concrete stream types such as std::cout, std::cin, std::ofstream, and std::ostringstream derive from basic_ostream, providing writable output

type
(defaulting
to
std::char_traits<charT>).
basic_ostream
inherits
from
std::basic_ios<charT,
Traits>
and
relies
on
a
stream
buffer
(std::basic_streambuf<charT,
Traits>),
accessed
via
rdbuf(),
to
perform
the
actual
I/O.
with
seekp
and
tellp.
It
also
exposes
formatting
state—width,
precision,
fill
and
the
format
flags—through
setf,
unsetf
and
related
accessors.
The
insertion
operators
(operator<<)
for
a
wide
range
of
types
ultimately
dispatch
through
these
facilities
and
the
num_put
locale
facet
to
render
values
as
text.
aliases
and
specializations,
allowing
different
character
encodings
to
be
written
through
the
same
interface.
to
the
console,
files,
or
in-memory
buffers.
The
class
plays
a
central
role
in
the
iostreams
library
by
coordinating
formatting,
buffering,
and
the
insertion-based
output
interface
used
throughout
C++.