[locale.nm.put]

# 28 Text processing library [[text]](./#text)

## 28.3 Localization library [[localization]](localization#locale.nm.put)

### 28.3.4 Standard locale categories [[locale.categories]](locale.categories#locale.nm.put)

#### 28.3.4.3 The numeric category [[category.numeric]](category.numeric#locale.nm.put)

#### 28.3.4.3.3 Class template num_put [locale.nm.put]

#### [28.3.4.3.3.1](#general) General [[locale.nm.put.general]](locale.nm.put.general)

[ð](#lib:num_put)

namespace std {template<class charT, class OutputIterator = ostreambuf_iterator<charT>>class num_put : public locale::facet {public:using char_type = charT; using iter_type = OutputIterator; explicit num_put(size_t refs = 0);

 iter_type put(iter_type s, ios_base& f, char_type fill, bool v) const;
 iter_type put(iter_type s, ios_base& f, char_type fill, long v) const;
 iter_type put(iter_type s, ios_base& f, char_type fill, long long v) const;
 iter_type put(iter_type s, ios_base& f, char_type fill, unsigned long v) const;
 iter_type put(iter_type s, ios_base& f, char_type fill, unsigned long long v) const;
 iter_type put(iter_type s, ios_base& f, char_type fill, double v) const;
 iter_type put(iter_type s, ios_base& f, char_type fill, long double v) const;
 iter_type put(iter_type s, ios_base& f, char_type fill, const void* v) const; static locale::id id; protected:~num_put(); virtual iter_type do_put(iter_type, ios_base&, char_type fill, bool v) const; virtual iter_type do_put(iter_type, ios_base&, char_type fill, long v) const; virtual iter_type do_put(iter_type, ios_base&, char_type fill, long long v) const; virtual iter_type do_put(iter_type, ios_base&, char_type fill, unsigned long) const; virtual iter_type do_put(iter_type, ios_base&, char_type fill, unsigned long long) const; virtual iter_type do_put(iter_type, ios_base&, char_type fill, double v) const; virtual iter_type do_put(iter_type, ios_base&, char_type fill, long double v) const; virtual iter_type do_put(iter_type, ios_base&, char_type fill, const void* v) const; };}

[1](#general-1)

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

The facetnum_put is used to format numeric values to a character sequence such as an ostream[.](#general-1.sentence-1)

#### [28.3.4.3.3.2](#facet.num.put.members) Members [[facet.num.put.members]](facet.num.put.members)

[ð](#lib:num_put,put)

`iter_type put(iter_type out, ios_base& str, char_type fill, bool val) const;
iter_type put(iter_type out, ios_base& str, char_type fill, long val) const;
iter_type put(iter_type out, ios_base& str, char_type fill, long long val) const;
iter_type put(iter_type out, ios_base& str, char_type fill, unsigned long val) const;
iter_type put(iter_type out, ios_base& str, char_type fill, unsigned long long val) const;
iter_type put(iter_type out, ios_base& str, char_type fill, double val) const;
iter_type put(iter_type out, ios_base& str, char_type fill, long double val) const;
iter_type put(iter_type out, ios_base& str, char_type fill, const void* val) const;
`

[1](#facet.num.put.members-1)

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

*Returns*: do_put(out, str, fill, val)[.](#facet.num.put.members-1.sentence-1)

#### [28.3.4.3.3.3](#facet.num.put.virtuals) Virtual functions [[facet.num.put.virtuals]](facet.num.put.virtuals)

[ð](#lib:num_put,do_put)

`iter_type do_put(iter_type out, ios_base& str, char_type fill, long val) const;
iter_type do_put(iter_type out, ios_base& str, char_type fill, long long val) const;
iter_type do_put(iter_type out, ios_base& str, char_type fill, unsigned long val) const;
iter_type do_put(iter_type out, ios_base& str, char_type fill, unsigned long long val) const;
iter_type do_put(iter_type out, ios_base& str, char_type fill, double val) const;
iter_type do_put(iter_type out, ios_base& str, char_type fill, long double val) const;
iter_type do_put(iter_type out, ios_base& str, char_type fill, const void* val) const;
`

[1](#facet.num.put.virtuals-1)

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

*Effects*: Writes characters to the sequence out,
formatting val as desired[.](#facet.num.put.virtuals-1.sentence-1)

In the following description, loc names a local variable initialized aslocale loc = str.getloc();

[2](#facet.num.put.virtuals-2)

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

The details of this operation occur in several stages:

- [(2.1)](#facet.num.put.virtuals-2.1)

  Stage 1:
Determine a printf conversion specifier spec and
determine the characters
that would be printed by printf ([[c.files]](c.files "31.13 C library files"))
given this conversion specifier forprintf(spec, val) assuming that the current locale is the "C" locale[.](#facet.num.put.virtuals-2.1.sentence-1)

- [(2.2)](#facet.num.put.virtuals-2.2)

  Stage 2:
Adjust the representation by converting
each char determined by stage 1 to a charT using a conversion and
values returned by members of use_facet<numpunct<charT>>(loc)[.](#facet.num.put.virtuals-2.2.sentence-1)

- [(2.3)](#facet.num.put.virtuals-2.3)

  Stage 3:
Determine where padding is required[.](#facet.num.put.virtuals-2.3.sentence-1)

- [(2.4)](#facet.num.put.virtuals-2.4)

  Stage 4:
Insert the sequence into the out[.](#facet.num.put.virtuals-2.4.sentence-1)

[3](#facet.num.put.virtuals-3)

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

Detailed descriptions of each stage follow[.](#facet.num.put.virtuals-3.sentence-1)

[4](#facet.num.put.virtuals-4)

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

*Returns*: out[.](#facet.num.put.virtuals-4.sentence-1)

[5](#facet.num.put.virtuals-5)

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

- [Stage 1:](#facet.num.put.virtuals-5.1)
  The first action of stage 1 is to determine a conversion specifier[.](#facet.num.put.virtuals-5.1.sentence-1)
  The tables that describe this determination use the following local variables
  fmtflags flags = str.flags();
fmtflags basefield = (flags & (ios_base::basefield));
fmtflags uppercase = (flags & (ios_base::uppercase));
fmtflags floatfield = (flags & (ios_base::floatfield));
fmtflags showpos = (flags & (ios_base::showpos));
fmtflags showbase = (flags & (ios_base::showbase));
fmtflags showpoint = (flags & (ios_base::showpoint));
  All tables used in describing stage 1 are ordered[.](#facet.num.put.virtuals-5.1.sentence-3)
  That is, the first line whose condition is true applies[.](#facet.num.put.virtuals-5.1.sentence-4)
  A line without a condition is the default behavior
when none of the earlier lines apply[.](#facet.num.put.virtuals-5.1.sentence-5)
  For conversion from an integral type other than a character type,
the function determines the integral conversion specifier
as indicated in Table [97](#tab:facet.num.put.int "Table 97: Integer conversions")[.](#facet.num.put.virtuals-5.1.sentence-6)
  Table [97](#tab:facet.num.put.int) — Integer conversions [[tab:facet.num.put.int]](./tab:facet.num.put.int)  

| [ð](#tab:facet.num.put.int-row-1)<br>   **State** | **stdio equivalent** |
| --- | --- |
| [ð](#tab:facet.num.put.int-row-2)<br>   basefield == ios_base​::​oct | %o |
| [ð](#tab:facet.num.put.int-row-3)<br>   (basefield == ios_base​::​hex) && !uppercase | %x |
| [ð](#tab:facet.num.put.int-row-4)<br>   (basefield == ios_base​::​hex) | %X |
| [ð](#tab:facet.num.put.int-row-5)<br>   for a signed integral type | %d |
| [ð](#tab:facet.num.put.int-row-6)<br>   for an unsigned integral type | %u |

  For conversion from a floating-point type,
the function determines the floating-point conversion specifier
as indicated in Table [98](#tab:facet.num.put.fp "Table 98: Floating-point conversions")[.](#facet.num.put.virtuals-5.1.sentence-7)
  Table [98](#tab:facet.num.put.fp) — Floating-point conversions [[tab:facet.num.put.fp]](./tab:facet.num.put.fp)  

| [ð](#tab:facet.num.put.fp-row-1)<br>   **State** | **stdio equivalent** |
| --- | --- |
| [ð](#tab:facet.num.put.fp-row-2)<br>   floatfield == ios_base​::​fixed && !uppercase | %f |
| [ð](#tab:facet.num.put.fp-row-3)<br>   floatfield == ios_base​::​fixed | %F |
| [ð](#tab:facet.num.put.fp-row-4)<br>   floatfield == ios_base​::​scientific && !uppercase | %e |
| [ð](#tab:facet.num.put.fp-row-5)<br>   floatfield == ios_base​::​scientific | %E |
| [ð](#tab:facet.num.put.fp-row-6)<br>   floatfield == (ios_base​::​fixed | ios_base​::​scientific) && !uppercase | %a |
| [ð](#tab:facet.num.put.fp-row-7)<br>   floatfield == (ios_base​::​fixed | ios_base​::​scientific) | %A |
| [ð](#tab:facet.num.put.fp-row-8)<br>   !uppercase | %g |
| [ð](#tab:facet.num.put.fp-row-9)<br>   *otherwise* | %G |

  For conversions from an integral or floating-point type
a length modifier is added to the conversion specifier
as indicated in Table [99](#tab:facet.num.put.length "Table 99: Length modifier")[.](#facet.num.put.virtuals-5.1.sentence-8)
  Table [99](#tab:facet.num.put.length) — Length modifier [[tab:facet.num.put.length]](./tab:facet.num.put.length)  

| [ð](#tab:facet.num.put.length-row-1)<br>   **Type** | **Length modifier** |
| --- | --- |
| [ð](#tab:facet.num.put.length-row-2)<br>   long | l |
| [ð](#tab:facet.num.put.length-row-3)<br>   long long | ll |
| [ð](#tab:facet.num.put.length-row-4)<br>   unsigned long | l |
| [ð](#tab:facet.num.put.length-row-5)<br>   unsigned long long | ll |
| [ð](#tab:facet.num.put.length-row-6)<br>   long double | L |
| [ð](#tab:facet.num.put.length-row-7)<br>   *otherwise* | *none* |

  The conversion specifier has the following optional additional qualifiers
prepended as indicated in Table [100](#tab:facet.num.put.conv "Table 100: Numeric conversions")[.](#facet.num.put.virtuals-5.1.sentence-9)
  Table [100](#tab:facet.num.put.conv) — Numeric conversions [[tab:facet.num.put.conv]](./tab:facet.num.put.conv)  

| [ð](#tab:facet.num.put.conv-row-1)<br>   **Type(s)** | **State** | **stdio equivalent** |
| --- | --- | --- |
| [ð](#tab:facet.num.put.conv-row-2)<br>   an integral type | showpos | + |
| [ð](#tab:facet.num.put.conv-row-3) | showbase | # |
| [ð](#tab:facet.num.put.conv-row-4)<br>   a floating-point type | showpos | + |
| [ð](#tab:facet.num.put.conv-row-5) | showpoint | # |

  For conversion from a floating-point type,
if floatfield != (ios_base​::​fixed | ios_base​::​​scientific),str.precision() is specified as precision
in the conversion specification[.](#facet.num.put.virtuals-5.1.sentence-10)
  Otherwise, no precision is specified[.](#facet.num.put.virtuals-5.1.sentence-11)
  For conversion from void* the specifier is %p[.](#facet.num.put.virtuals-5.1.sentence-12)
  The representations at the end of stage 1 consists of the char's
that would be printed by a call of printf(s, val) where s is the conversion specifier determined above[.](#facet.num.put.virtuals-5.1.sentence-13)

- [Stage 2:](#facet.num.put.virtuals-5.2)
  Any character c other than a decimal point(.) is converted to
a charT viause_facet<ctype<charT>>(loc).widen(c)
  A local variable punct is initialized viaconst numpunct<charT>& punct = use_facet<numpunct<charT>>(loc);
  For arithmetic types,punct.thousands_sep() characters are inserted into
the sequence as determined by the value returned by punct.do_grouping() using the method described in [[facet.numpunct.virtuals]](facet.numpunct.virtuals "28.3.4.4.1.3 Virtual functions")[.](#facet.num.put.virtuals-5.2.sentence-3)
  Decimal point characters(.) are replaced by punct.decimal_point()[.](#facet.num.put.virtuals-5.2.sentence-4)

- [Stage 3:](#facet.num.put.virtuals-5.3)
  A local variable is initialized asfmtflags adjustfield = (flags & (ios_base::adjustfield));
  The location of any padding[224](#footnote-224 "The conversion specification #o generates a leading 0 which is not a padding character.") is determined according to Table [101](#tab:facet.num.put.fill "Table 101: Fill padding")[.](#facet.num.put.virtuals-5.3.sentence-2)
  Table [101](#tab:facet.num.put.fill) — Fill padding [[tab:facet.num.put.fill]](./tab:facet.num.put.fill)  

| [ð](#tab:facet.num.put.fill-row-1)<br>   **State** | **Location** |
| --- | --- |
| [ð](#tab:facet.num.put.fill-row-2)<br>   adjustfield == ios_base​::​left | pad after |
| [ð](#tab:facet.num.put.fill-row-3)<br>   adjustfield == ios_base​::​right | pad before |
| [ð](#tab:facet.num.put.fill-row-4)<br>   adjustfield == internal and a sign occurs in the representation | pad after the sign |
| [ð](#tab:facet.num.put.fill-row-5)<br>   adjustfield == internal and representation after stage 1 began with 0x or 0X | pad after x or X |
| [ð](#tab:facet.num.put.fill-row-6)<br>   *otherwise* | pad before |

  If str.width() is nonzero and the number of charT's
in the sequence after stage 2 is less than str.​width(),
then enough fill characters are added to the sequence
at the position indicated for padding
to bring the length of the sequence to str.width()[.](#facet.num.put.virtuals-5.3.sentence-3)
  str.width(0) is called[.](#facet.num.put.virtuals-5.3.sentence-4)

- [Stage 4:](#facet.num.put.virtuals-5.4)
  The sequence of charT's at the end of stage 3 are output via*out++ = c

[ð](#lib:do_put,num_put_)

`iter_type do_put(iter_type out, ios_base& str, char_type fill, bool val) const;
`

[6](#facet.num.put.virtuals-6)

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

*Returns*: If (str.flags() & ios_base​::​boolalpha) == 0 returns do_put(out, str, fill,  
(int)val),
otherwise obtains a string s as if bystring_type s = val ? use_facet<numpunct<charT>>(loc).truename(): use_facet<numpunct<charT>>(loc).falsename(); and then inserts each character c of s into out via *out++ = c and returns out[.](#facet.num.put.virtuals-6.sentence-1)

[224)](#footnote-224)[224)](#footnoteref-224)

The conversion specification #o generates a leading 0 which is *not* a padding character[.](#footnote-224.sentence-1)
