[ostream.inserters.arithmetic]

# 31 Input/output library [[input.output]](./#input.output)

## 31.7 Formatting and manipulators [[iostream.format]](iostream.format#ostream.inserters.arithmetic)

### 31.7.6 Output streams [[output.streams]](output.streams#ostream.inserters.arithmetic)

#### 31.7.6.3 Formatted output functions [[ostream.formatted]](ostream.formatted#ostream.inserters.arithmetic)

#### 31.7.6.3.2 Arithmetic inserters [ostream.inserters.arithmetic]

[ð](#lib:operator%3c%3c,basic_ostream)

`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);
`

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L6427)

*Effects*: The classesnum_get<> andnum_put<> handle locale-dependent numeric formatting and
parsing[.](#1.sentence-1)

These inserter functions use the imbuedlocale value to perform numeric formatting[.](#1.sentence-2)

When val is 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 typeshort the 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 typeint the 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 short orunsigned int 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<unsigned long>(val)).failed();

When val is of typefloat 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();

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L6496)

The first argument provides an object of theostreambuf_iterator<> class which is an iterator for class basic_ostream<>[.](#2.sentence-1)

It bypassesostreams
and usesstreambufs
directly[.](#2.sentence-2)

Classlocale relies on these types as its
interface to iostreams, since for flexibility it has been abstracted
away from direct dependence onostream[.](#2.sentence-3)

The second parameter is a reference to the base class subobject of typeios_base[.](#2.sentence-4)

It provides formatting specifications such as field width, and
a locale from which to obtain other facets[.](#2.sentence-5)

Iffailed istrue then doessetstate(badbit),
which may throw an exception, and returns[.](#2.sentence-6)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L6523)

*Returns*: *this[.](#3.sentence-1)

[ð](#lib:operator%3c%3c,basic_ostream_)

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

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L6534)

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

[ð](#itemdecl:3)

`basic_ostream& operator<<(extended-floating-point-type val);
`

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L6544)

*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[.](#5.sentence-3)

If failed is true then does setstate(badbit),
which may throw an exception, and returns[.](#5.sentence-4)

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L6568)

*Returns*: *this[.](#6.sentence-1)
