Provides formatted insertion of types into a stream.
basic_ostream<charT, traits>& operator<<(short n) basic_ostream<charT, traits>& operator<<(unsigned short n) basic_ostream<charT, traits>& operator<<(int n) basic_ostream<charT, traits>& operator<<(unsigned int n) basic_ostream<charT, traits>& operator<<(long n) basic_ostream<charT, traits>& operator<<(unsigned long n) basic_ostream<charT, traits>& operator<<(float f) basic_ostream<charT, traits>& operator<<(double f) basic_ostream<charT, traits>& operator<<(long double f)
Converts an arithmetic value. The formatted values are converted as if they had the same behavior of the fprintf() function.
In most cases *this is returned unless failure, in which case set state(failbit) is called.
| Output State | stdio equivalent |
|---|---|
| Integers | |
| (flags() & basefield) == oct | %o |
| (flags() & basefield) == hex | %x |
| (flags() & basefield) != 0 | %x |
| Otherwise | |
| signed integral type | %d |
| unsigned integral type | %u |
| Floating Point Numbers | |
| (flags() & floatfield) == fixed | %f |
| (flags() & floatfield) == scientific (flags() & uppercase) != 0 | %e %E |
| Otherwise | |
| (flags() & uppercase) != 0 | %g %G |
| An integral type other than a char type | |
| (flags() & showpos) != 0 (flags() & showbase) != 0 | + # |
| A floating point type | |
| (flags() & showpos) != 0 (flags() & showpoint) != 0 | + # |
For any conversion, if width() is non-zero then a field with a conversion specification has the value of width().
For any conversion, if (flags() and fixed) !=0 or if precision() >0 the conversion specification is the value of precision().
For any conversion, padding behaves in the following manner.
| State | Justification | stdio equivalent |
|---|---|---|
| (flags()& adjustfield) == left | left | space padding |
| (flags() & adjustfield) == internal | Internal | zero padding |
| Otherwise | right | space padding |
The ostream insertion operators are overloaded to provide for insertion of most predefined types into an output stream. They return a reference to the basic stream object so they may be used in a chain of statements to input various types to the same stream.