std::num_put<CharT,OutputIt>::put, std::num_put<CharT,OutputIt>::do_put

Header: <locale>

  1. Public member function, calls the protected virtual member function do_put of the most derived class.

# Declarations

public:
iter_type put( iter_type out, std::ios_base& str,
char_type fill, bool val ) const;
iter_type put( iter_type out, std::ios_base& str,
char_type fill, long val ) const;
iter_type put( iter_type out, std::ios_base& str,
char_type fill, long long val ) const;

(since C++11)

iter_type put( iter_type out, std::ios_base& str,
char_type fill, unsigned long val ) const;
iter_type put( iter_type out, std::ios_base& str,
char_type fill, unsigned long long val ) const;

(since C++11)

iter_type put( iter_type out, std::ios_base& str,
char_type fill, double val ) const;
iter_type put( iter_type out, std::ios_base& str,
char_type fill, long double val ) const;
iter_type put( iter_type out, std::ios_base& str,
char_type fill, const void* val ) const;
protected:
virtual iter_type do_put( iter_type out, std::ios_base& str,
char_type fill, bool val ) const;
virtual iter_type do_put( iter_type out, std::ios_base& str,
char_type fill, long val ) const;
virtual iter_type do_put( iter_type out, std::ios_base& str,
char_type fill, long long val ) const;

(since C++11)

virtual iter_type do_put( iter_type out, std::ios_base& str,
char_type fill, unsigned long val ) const;
virtual iter_type do_put( iter_type out, std::ios_base& str,
char_type fill, unsigned long long val ) const;

(since C++11)

virtual iter_type do_put( iter_type out, std::ios_base& str,
char_type fill, double val ) const;
virtual iter_type do_put( iter_type out, std::ios_base& str,
char_type fill, long double val ) const;
virtual iter_type do_put( iter_type out, std::ios_base& str,
char_type fill, const void* val ) const;

# Parameters

# 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.

# Example

#include <iostream>
#include <locale>
 
// this custom num_put outputs squares of all integers (except long long)
struct squaring_num_put : std::num_put<char>
{
    iter_type do_put(iter_type out, std::ios_base& str,
                     char_type fill, long val) const
    {
        return std::num_put<char>::do_put(out, str, fill, val * val);
    }
 
    iter_type do_put(iter_type out, std::ios_base& str,
                     char_type fill, unsigned long val) const
    {
        return std::num_put<char>::do_put(out, str, fill, val * val);
    }
};
 
int main()
{
    auto& facet = std::use_facet<std::num_put<char>>(std::locale());
    facet.put(std::cout, std::cout, '0', 2.71);
    std::cout << '\n';
 
    std::cout.imbue(std::locale(std::cout.getloc(), new squaring_num_put));
    std::cout << 6 << ' ' << -12 << '\n';
}

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 34C++98the bool overload used non-existing memberstruename and falsename of std::ctypeuse these members of std::numpunct
LWG 231C++98the precision modifier was only added if(flags & fixed) != 0 or str.precision() > 0removed these conditions
LWG 282C++98the thousand separators were only inserted for integral types in stage 2also inserted for floating-point types

# See also