std::num_put<CharT,OutputIt>::put,std::num_put<CharT,OutputIt>::do_put (3) - Linux Manuals
std::num_put<CharT,OutputIt>::put,std::num_put<CharT,OutputIt>::do_put: std::num_put<CharT,OutputIt>::put,std::num_put<CharT,OutputIt>::do_put
NAME
std::num_put<CharT,OutputIt>::put,std::num_put<CharT,OutputIt>::do_put - std::num_put<CharT,OutputIt>::put,std::num_put<CharT,OutputIt>::do_put
Synopsis
Defined in header <locale>
public:
iter_type put( iter_type out, std::ios_base& str, char_type fill, bool v ) const;
iter_type put( iter_type out, std::ios_base& str, char_type fill, long v ) const;
iter_type put( iter_type out, std::ios_base& str, char_type fill, long long v ) const; (since C++11)
iter_type put( iter_type out, std::ios_base& str, char_type fill, unsigned long v ) const;
iter_type put( iter_type out, std::ios_base& str, char_type fill, unsigned long long v ) const; (since C++11)
iter_type put( iter_type out, std::ios_base& str, char_type fill, double v ) const;
iter_type put( iter_type out, std::ios_base& str, char_type fill, long double v ) const;
iter_type put( iter_type out, std::ios_base& str, char_type fill, const void* v ) const; (1)
protected:
virtual iter_type do_put( iter_type out, std::ios_base& str, char_type fill, bool v ) const;
virtual iter_type do_put( iter_type out, std::ios_base& str, char_type fill, long v ) const;
virtual iter_type do_put( iter_type out, std::ios_base& str, char_type fill, long long v ) const; (since C++11)
virtual iter_type do_put( iter_type out, std::ios_base& str, char_type fill, unsigned long ) const; (2)
virtual iter_type do_put( iter_type out, std::ios_base& str, char_type fill, unsigned long long ) const; (since C++11)
virtual iter_type do_put( iter_type out, std::ios_base& str, char_type fill, double v ) const;
virtual iter_type do_put( iter_type out, std::ios_base& str, char_type fill, long double v ) const;
virtual iter_type do_put( iter_type out, std::ios_base& str, char_type fill, const void* v ) const;
1) Public member function, calls the protected virtual member function do_put of the most derived class.
2) Writes characters to the output sequence out which represent the value of v, formatted as requested by the formatting flags str.flags() and the std::numpunct and std::ctype facets of the locale imbued in the stream str. This function is called by all formatted output stream operators, such as std::cout << n;.
Conversion occurs in four stages
Stage 1: conversion specifier selection
* I/O format flags are obtained, as if by
* If the type of v is bool
* If the type of v is an integer type, the the first applicable choice of the following is selected:
* For integer types, length modifier is added to the conversion specification if necessary: l for long and unsigned long
* If the type of v is a floating-point type, the the first applicable choice of the following is selected:
* For both integer and floating-point types, if showpos is set, the modifier + is prepended
* For integer types, if showbase is set, the modifier # is prepended.
* For floating-point types, if showpoint is set, the modifier # is prepended.
* If the type of v is void*, will use conversion specifier %p
* A narrow character string is created as if by a call to std::printf(spec, v) in the "C" locale, where spec is the chosen conversion specifier.
Stage 2: locale-specific conversion
* Every character c obtained in Stage 1, other than the decimal point '.', is converted to CharT by calling std::use_facet<std::ctype<CharT>>(str.getloc()).widen(c).
* For arithmetic types, the thousands separator character, obtained from std::use_facet<std::numpunct<CharT>>(str.getloc()).thousands_sep(), is inserted into the sequence according to the grouping rules provided by std::use_facet<std::numpunct<CharT>>(str.getloc()).grouping()
* Decimal point characters ('.') are replaced by std::use_facet<std::numpunct<CharT>>(str.getloc()).decimal_point()
Stage 3: padding
* The adjustment flag is obtained as if by std::fmtflags adjustfield = (flags & (std::ios_base::adjustfield)) and examined to identify padding location, as follows
* If str.width() is non-zero (e.g. std::setw was just used) and the number of CharT's after Stage 2 is less than str.width(), then copies of the fill character are inserted at the position indicated by padding to bring the length of the sequence to str.width().
In any case, str.width(0) is called to cancel the effects of std::setw.
Stage 4: output
Every successive character c from the sequence of CharT's from Stage 3 is output as if by *out++ = c.
Parameters
out - iterator pointing to the first character to be overwritten
str - stream to retrieve the formatting information from
fill - padding character used when the results needs to be padded to the field width
v - value to convert to string and output
Return value
out
Notes
The leading zero generated by the conversion specification #o (resulting from the combination of std::showbase and std::oct for example) is not counted as a padding character.
When formatting a floating point value as hexfloat (i.e., when floatfield == (std::ios_base::fixed | std::ios_base::scientific)), the stream's precision is not used; instead, the number is always printed with enough precision to exactly represent the value. (since C++11)
Example
Output a number using the facet directly, and demonstrate user-defined facet
// Run this code