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

Header: <locale>

Converts the calendar date and time stored in the std::tm object pointed to by t into a character string, according to the format string [fmtbeg, fmtend). The format string is the same as used by std::strftime, but each format specifier is processed by an individual call to do_put(), which can be customized by extending this facet.

# Declarations

public:
iter_type put( iter_type out, std::ios_base& str,
char_type fill, const std::tm* t,
const CharT* fmtbeg, const CharT* fmtend ) const;
public:
iter_type put( iter_type out, std::ios_base& str,
char_type fill, const std::tm* t,
char format, char modifier = 0 ) const;
protected:
virtual iter_type do_put( iter_type out, std::ios_base& str,
char_type fill, const std::tm* t,
char format, char modifier ) const;

# Parameters

# Return value

Iterator pointing one past the last character that was produced.

# Notes

No error handling is provided.

The fill character is provided for those implementation-defined format specifiers and for the user-defined overrides of do_put() that use padding and filling logic. Such implementations typically make use of the formatting flags from str.

# Example

#include <iostream>
#include <sstream>
#include <iomanip>
#include <ctime>
 
void try_time_put(const std::tm* t, const std::string& fmt)
{
    std::cout.imbue(std::locale());
    std::cout << "In the locale '" << std::cout.getloc().name() << "' : '";
 
    std::use_facet<std::time_put<char>>(std::cout.getloc()).put(
        {std::cout}, std::cout, ' ', t, &fmt[0], &fmt[0] + fmt.size());
 
    std::cout << "'\n";
}
 
int main()
{
    std::time_t t = std::time(NULL);
    std::tm tm = *std::localtime(&t);
 
    std::string fmt = "%c";
    std::cout << "Using the format string '" << fmt
              << "' to format the time: " << std::ctime(&t) << '\n';
 
    std::locale::global(std::locale("de_DE.utf8"));
    try_time_put(&tm, fmt);
 
    std::locale::global(std::locale("el_GR.utf8"));
    try_time_put(&tm, fmt);
 
    std::locale::global(std::locale("ja_JP.utf8"));
    try_time_put(&tm, fmt);
}

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 164C++98the purpose of the parameter fill was not clearmade clear

# See also