[ostream.inserters.arithmetic] (original) (raw)

31 Input/output library [input.output]

31.7 Formatting and manipulators [iostream.format]

31.7.6 Output streams [output.streams]

31.7.6.3 Formatted output functions [ostream.formatted]

31.7.6.3.2 Arithmetic inserters [ostream.inserters.arithmetic]

basic_ostream& operator<<(bool val); basic_ostream& operator<<(short val); basic_ostream& operator<<(unsigned short val); basic_ostream& operator<<(int val); basic_ostream& operator<<(unsigned int val); basic_ostream& operator<<(long val); basic_ostream& operator<<(unsigned long val); basic_ostream& operator<<(long long val); basic_ostream& operator<<(unsigned long long val); basic_ostream& operator<<(float val); basic_ostream& operator<<(double val); basic_ostream& operator<<(long double val); basic_ostream& operator<<(const void* val);

Effects: The classesnum_get<>andnum_put<>handle locale-dependent numeric formatting and parsing.

These inserter functions use the imbuedlocalevalue to perform numeric formatting.

When valis of typebool,long,unsigned long,long long, unsigned long long,double,long double, orconst void*, the formatting conversion occurs as if it performed the following code fragment:bool failed = use_facet<num_put<charT, ostreambuf_iterator<charT, traits>>>( getloc()).put(*this, *this, fill(), val).failed();

When val is of typeshortthe formatting conversion occurs as if it performed the following code fragment:ios_base::fmtflags baseflags = ios_base::flags() & ios_base::basefield;bool failed = use_facet<num_put<charT, ostreambuf_iterator<charT, traits>>>( getloc()).put(*this, *this, fill(), baseflags == ios_base::oct || baseflags == ios_base::hex? static_cast<long>(static_cast<unsigned short>(val)) : static_cast<long>(val)).failed();

When val is of typeintthe formatting conversion occurs as if it performed the following code fragment:ios_base::fmtflags baseflags = ios_base::flags() & ios_base::basefield;bool failed = use_facet<num_put<charT, ostreambuf_iterator<charT, traits>>>( getloc()).put(*this, *this, fill(), baseflags == ios_base::oct || baseflags == ios_base::hex? static_cast<long>(static_cast<unsigned int>(val)) : static_cast<long>(val)).failed();

When val is of typeunsigned shortorunsigned intthe formatting conversion occurs as if it performed the following code fragment:bool failed = use_facet<num_put<charT, ostreambuf_iterator<charT, traits>>>( getloc()).put(*this, *this, fill(), static_cast<unsigned long>(val)).failed();

When val is of typefloatthe formatting conversion occurs as if it performed the following code fragment:bool failed = use_facet<num_put<charT, ostreambuf_iterator<charT, traits>>>( getloc()).put(*this, *this, fill(), static_cast<double>(val)).failed();

The first argument provides an object of theostreambuf_iterator<>class which is an iterator for class basic_ostream<>.

It bypassesostreams and usesstreambufs directly.

Classlocalerelies on these types as its interface to iostreams, since for flexibility it has been abstracted away from direct dependence onostream.

The second parameter is a reference to the base class subobject of typeios_base.

It provides formatting specifications such as field width, and a locale from which to obtain other facets.

Iffailedistruethen doessetstate(badbit), which may throw an exception, and returns.

basic_ostream& operator<<(const volatile void* p);

Effects: Equivalent to: return operator<<(const_cast<const void*>(p));

basic_ostream& operator<<(_extended-floating-point-type_ val);

Effects: If the floating-point conversion rank of _extended-floating-point-type_is less than or equal to that of double, the formatting conversion occurs as if it performed the following code fragment:bool failed = use_facet<num_put<charT, ostreambuf_iterator<charT, traits>>>( getloc()).put(*this, *this, fill(), static_cast<double>(val)).failed();

Otherwise, if the floating-point conversion rank of _extended-floating-point-type_is less than or equal to that of long double, the formatting conversion occurs as if it performed the following code fragment:bool failed = use_facet<num_put<charT, ostreambuf_iterator<charT, traits>>>( getloc()).put(*this, *this, fill(), static_cast<long double>(val)).failed();

Otherwise, an invocation of the operator function is conditionally supported with implementation-defined semantics.

If failed is true then does setstate(badbit), which may throw an exception, and returns.