Inserts data into the stream.
FormattedOutputFunction
. After constructing and checking the sentry object, if value
is short
or int
, then casts it to unsigned short
or unsigned int
if ios_base::flags() & ios_base::basefield
is ios_base::oct
or ios_base::hex
. After that, casts to long
in any case and outputs as in (3). If value
is unsigned short
or unsigned int
, casts to unsigned long
and outputs as in (3).FormattedOutputFunction
. After constructing and checking the sentry object, inserts an integer, floating point, boolean or generic pointer value by calling num_put::put()
. If the end of file condition was encountered during output (put().failed() == true
), sets ios::badbit
.*this << s
, where s
is a null-terminated character type string.UnformattedOutputFunction
. After constructing and checking the sentry object, checks if sb
is a null pointer. If it is, executes setstate(badbit)
and exits. Otherwise, extracts characters from the input sequence controlled by sb
and inserts them into *this
until one of the following conditions are met: setstate(failbit)
. If an exception was thrown while extracting, sets failbit
and, if failbit
is set in exceptions()
, rethrows the exception.func(*this);
. These overloads are used to implement output I/O manipulators such as std::endl
.value | - | integer, floating-point, boolean, or pointer value to insert |
func | - | function to call |
sb | - | pointer to the streambuffer to read the data from |
*this
func(*this)
There are no overload for pointers to non-static member, pointers to volatile, or function pointers (other than the ones with signatures accepted by the (10-12) overloads). Attempting to output such objects invokes implicit conversion to bool
, and, for any non-null pointer value, the value 1
is printed (unless boolalpha
was set).
Character and character string arguments (e.g., of type char
or const char*
) are handled by the non-member overloads of operator<<
. Attempting to output a character using the member function call syntax (e.g., std::cout.operator<<('c');
) will call one of overloads (2-4) and output the numerical value. Attempting to output a character string using the member function call syntax will call overload (7) and print the pointer value instead.
#include <iostream> #include <iomanip> #include <sstream> int main() { std::istringstream input(" \"Some text.\" "); volatile int n = 42; double f = 3.14; bool b = true; std::cout << n // int overload << ' ' // non-member overload << std::boolalpha << b // bool overload << " " // non-member overload << std::fixed << f // double overload << input.rdbuf() // streambuf overload << &n // bool overload: volatile int* doesn't convert to const void* << std::endl; // function overload }
Output:
inserts character data (function template) |
|
performs stream I/O of strings (function template) |
|
performs stream input and output of bitsets (function) |
|
serializes and deserializes a complex number (function template) |
|
performs stream input and output on pseudo-random number engine (function template) |
|
performs stream input and output on pseudo-random number distribution (function template) |
|
inserts a character (public member function) |
|
inserts blocks of characters (public member function) |
|
(C++17) | converts an integer or floating-point value to a character sequence (function) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/io/basic_ostream/operator_ltlt