此类模板描述一个用作区域设置 facet 的对象,可用于控制时间值向 CharType 类型序列的转换。
语法
template <class CharType,
class OutputIterator = ostreambuf_iterator<CharType>>
class time_put : public locale::facet;
参数
CharType
在程序中用于对字符进行编码的类型。
OutputIterator
供时间放置函数写入其输出结果的迭代器类型。
注解
对于任何区域设置 facet,静态对象 ID 的初始存储值为零。 首次尝试访问其存储值后,将在 ID 中存储唯一正值。
构造函数
| 构造函数 | 说明 |
|---|---|
| time_put |
time_put 类型的对象的构造函数。 |
Typedef
| 类型名称 | 说明 |
|---|---|
| char_type | 一种类型,此类型用于描述区域设置使用的字符。 |
| iter_type | 一种类型,此类型描述输出迭代器。 |
成员函数
| 成员函数 | 说明 |
|---|---|
| do_put | 一种以 CharType 序列的形式输出时间和日期信息的虚拟函数。 |
| put | 以 CharType 的形式输出时间和日期信息。 |
要求
标头:<locale>
命名空间: std
time_put::char_type
一种类型,此类型用于描述区域设置使用的字符。
typedef CharType char_type;
注解
该类型是模板参数 CharType 的同义词。
time_put::d o_put
一种以 CharType 序列的形式输出时间和日期信息的虚拟函数。
virtual iter_type do_put(
iter_type next,
ios_base& _Iosbase,
const tm* _Pt,
char _Fmt,
char _Mod = 0) const;
参数
下一步
一个输出迭代器,其中字符序列表示要插入的时间和日期。
_Iosbase
未使用。
_Pt
输出的时间和日期信息。
_Fmt
输出格式。 有关有效值的范围,请参阅 strftime、wcsftime、_strftime_l、_wcsftime_l。
_Mod
格式的修饰符。 有关有效值的范围,请参阅 strftime、wcsftime、_strftime_l、_wcsftime_l。
返回值
插入最后一个元素后第一个位置的迭代器。
注解
受保护的虚拟成员函数从存储于对象 * next(类型 _Pt)中的时间值生成开始于 tm 的有序元素。 该函数返回一个迭代器,指定在生成的输出外下一个要插入元素的位置。
通过使用与 strftime 相同的规则生成输出,最后一个参数为 _Pt,用于在数组中生成一系列 元素char。 假定将每个这样的 char 元素通过简单的、一对一的映射映射到 CharType 类型的等效元素。 如果 _Mod 等于零,有效格式为“%F”,其中 F 替换为 _Fmt。 否则,有效格式为“%MF”,其中 M 替换为 _Mod。
示例
请参阅 put 的示例,它调用 do_put。
time_put::iter_type
一种类型,此类型描述输出迭代器。
typedef OutputIterator iter_type;
注解
该类型是模板参数 OutputIterator 的同义词。
time_put::p ut
以 CharType 的形式输出时间和日期信息。
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;
参数
下一步
一个输出迭代器,其中字符序列表示要插入的时间和日期。
_Iosbase
未使用。
_Fill
用于间距的 CharType 类型的字符。
_Pt
输出的时间和日期信息。
_Fmt
输出格式。 有关有效值的范围,请参阅 strftime、wcsftime、_strftime_l、_wcsftime_l。
_Mod
格式的修饰符。 有关有效值的范围,请参阅 strftime、wcsftime、_strftime_l、_wcsftime_l。
第一
输出格式字符串的开头。 有关有效值的范围,请参阅 strftime、wcsftime、_strftime_l、_wcsftime_l。
最后
输出格式字符串的末尾。 有关有效值的范围,请参阅 strftime、wcsftime、_strftime_l、_wcsftime_l。
返回值
插入最后一个元素后第一个位置的迭代器。
注解
第一个成员函数返回 do_put(next、_Iosbase、_Fill、_Pt、_Fmt 和 _Mod)。 第二个成员函数复制到 * next ++ [ first, last) 间隔中的任何元素而不是百分号 (%)。 对于间隔中后跟字符 first 的百分比,last函数将改为计算next = do_put(next、、、_Iosbase、_Fill_PtC、0)并跳过 C。但是,如果 C 是集 EOQ# 中的限定符字符,后跟间隔中的字符 C2 [first,last),则函数将改为计算next = do_put (next、 、 、 _Iosbase、 _Fill_PtC2、 、 C) 并跳过过去。C2
示例
// 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
类型为 time_put 的对象的构造函数。
explicit time_put(size_t _Refs = 0);
参数
_Refs
用于指定对象的内存管理类型的整数值。
注解
_Refs 参数可能的值及其含义:
0:对象的生存期由包含该对象的区域设置管理。
1:必须手动管理对象的生存期。
> 1:未定义这些值。
构造函数通过 locale::facet(_Refs) 初始化其基对象。