Home

cout

Cout is the standard output stream in the C++ programming language. It is an object of type std::ostream defined in the iostream header and resides in the std namespace. std::cout writes data to the standard output, typically the console, and is usually globally accessible as std::cout.

Data is sent to cout using the insertion operator, operator<<, which is overloaded for built-in types as

Formatting and manipulators: cout maintains a formatting state that includes width, precision, fill character, and format

Performance and behavior: By default, iostreams may be synchronized with the C stdio library, which can be

User-defined types: To output custom types with cout, one typically provides an overloaded operator<< for std::ostream&

well
as
many
standard
library
types.
The
operator<<
returns
a
reference
to
the
stream,
enabling
chaining
of
inserts
in
a
single
expression.
Example:
std::cout
<<
"Hello,
"
<<
name
<<
'!'
<<
std::endl;
This
prints
the
string,
the
value
of
name,
a
exclamation
mark,
and
a
newline.
flags.
Formatting
can
be
controlled
with
manipulators
from
the
iomanip
header,
such
as
std::setw,
std::setprecision,
std::hex,
std::dec,
and
std::boolalpha.
std::endl
inserts
a
newline
and
flushes
the
stream,
while
std::flush
flushes
without
adding
a
newline.
For
wide
characters,
std::wcout
and
related
facilities
are
used.
disabled
with
std::ios::sync_with_stdio(false)
to
improve
performance
at
the
cost
of
interoperability
with
C
I/O.
std::cout
is
typically
tied
to
std::cin,
causing
cout
to
flush
before
input
operations.
The
stream
also
maintains
error
state
flags
(good,
fail,
bad,
eof)
that
can
be
checked
after
operations.
and
the
type,
enabling
seamless
streaming
of
objects.