time_put Class
The class template describes an object that can serve as a locale facet to control conversions of time values to sequences of type CharType
.
Syntax
template <class CharType,
class OutputIterator = ostreambuf_iterator<CharType>>
class time_put : public locale::facet;
Parameters
CharType
The type used within a program to encode characters.
OutputIterator
The type of iterator into which the time put functions write their output.
Remarks
As with any locale facet, the static object ID has an initial stored value of zero. The first attempt to access its stored value stores a unique positive value in id.
Constructors
Constructor | Description |
---|---|
time_put | The constructor for objects of type time_put . |
Typedefs
Type name | Description |
---|---|
char_type | A type that is used to describe a character used by a locale. |
iter_type | A type that describes an output iterator. |
Member functions
Member function | Description |
---|---|
do_put | A virtual function that outputs time and date information as a sequence of CharType s. |
put | Outputs time and date information as a sequence of CharType s. |
Requirements
Header: <locale>
Namespace: std
time_put::char_type
A type that is used to describe a character used by a locale.
typedef CharType char_type;
Remarks
The type is a synonym for the template parameter CharType
.
time_put::do_put
A virtual function that outputs time and date information as a sequence of CharType
s.
virtual iter_type do_put(
iter_type next,
ios_base& _Iosbase,
const tm* _Pt,
char _Fmt,
char _Mod = 0) const;
Parameters
next
An output iterator where the sequence of characters representing time and date are to be inserted.
_Iosbase
Unused.
_Pt
The time and date information being output.
_Fmt
The format of the output. See strftime, wcsftime, _strftime_l, _wcsftime_l for valid values.
_Mod
A modifier for the format. See strftime, wcsftime, _strftime_l, _wcsftime_l for valid values.
Return Value
An iterator to the first position after the last element inserted.
Remarks
The virtual protected member function generates sequential elements beginning at next
from time values stored in the object * _Pt
, of type tm
. The function returns an iterator designating the next place to insert an element beyond the generated output.
The output is generated by the same rules used by strftime
, with a last argument of _Pt, for generating a series of char
elements into an array. Each such char
element is assumed to map to an equivalent element of type CharType
by a simple, one-to-one mapping. If _Mod equals zero, the effective format is "%F", where F is replaced by _Fmt. Otherwise, the effective format is "%MF", where M is replaced by _Mod.
Example
See the example for put, which calls do_put
.
time_put::iter_type
A type that describes an output iterator.
typedef OutputIterator iter_type;
Remarks
The type is a synonym for the template parameter OutputIterator
.
time_put::put
Outputs time and date information as a sequence of CharType
s.
iter_type put(iter_type next,
ios_base& _Iosbase,
char_type _Fill,
const tm* _Pt,
char _Fmt,
char _Mod = 0) const;
iter_type put(iter_type next,
ios_base& _Iosbase,
char_type _Fill,
const tm* _Pt,
const CharType* first,
const CharType* last) const;
Parameters
next
An output iterator where the sequence of characters representing time and date are to be inserted.
_Iosbase
Unused.
_Fill
The character of type CharType
used for spacing.
_Pt
The time and date information being output.
_Fmt
The format of the output. See strftime, wcsftime, _strftime_l, _wcsftime_l for valid values.
_Mod
A modifier for the format. See strftime, wcsftime, _strftime_l, _wcsftime_l for valid values.
first
The beginning of the formatting string for the output. See strftime, wcsftime, _strftime_l, _wcsftime_l for valid values.
last
The end of the formatting string for the output. See strftime, wcsftime, _strftime_l, _wcsftime_l for valid values.
Return Value
An iterator to the first position after the last element inserted.
Remarks
The first member function returns do_put(next
, _Iosbase
, _Fill
, _Pt
, _Fmt
, _Mod
). The second member function copies to * next
++ any element in the interval [ first
, last
) other than a percent (%). For a percent followed by a character C in the interval [ first
, last
), the function instead evaluates next
= do_put
( next
, _Iosbase
, _Fill
, _Pt
, C, 0) and skips past C. If, however, C is a qualifier character from the set EOQ#, followed by a character C2
in the interval [ first
, last
), the function instead evaluates next
= do_put
( next
, _Iosbase
, _Fill
, _Pt
, C2
, C) and skips past C2
.
Example
// time_put_put.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>
#include <sstream>
#include <time.h>
using namespace std;
int main( )
{
locale loc;
basic_stringstream<char> pszPutI;
ios_base::iostate st = 0;
struct tm t;
memset( &t, 0, sizeof( struct tm ) );
t.tm_hour = 5;
t.tm_min = 30;
t.tm_sec = 40;
t.tm_year = 00;
t.tm_mday = 4;
t.tm_mon = 6;
pszPutI.imbue( loc );
char *pattern = "x: %X %x";
use_facet <time_put <char> >
(loc).put(basic_ostream<char>::_Iter(pszPutI.rdbuf( )),
pszPutI, ' ', &t, pattern, pattern+strlen(pattern));
cout << "num_put( ) = " << pszPutI.rdbuf( )->str( ) << endl;
char strftimebuf[255];
strftime(&strftimebuf[0], 255, pattern, &t);
cout << "strftime( ) = " << &strftimebuf[0] << endl;
}
num_put( ) = x: 05:30:40 07/04/00
strftime( ) = x: 05:30:40 07/04/00
time_put::time_put
Constructor for objects of type time_put
.
explicit time_put(size_t _Refs = 0);
Parameters
_Refs
Integer value used to specify the type of memory management for the object.
Remarks
The possible values for the _Refs parameter and their significance are:
0: The lifetime of the object is managed by the locales that contain it.
1: The lifetime of the object must be manually managed.
> 1: These values are not defined.
The constructor initializes its base object with locale::facet(_Refs).
See also
<locale>
time_base Class
Thread Safety in the C++ Standard Library