std::time_put
来自 cppreference.cn
定义于头文件 <locale> |
||
template< class CharT, |
||
类模板 std::time_put
封装了日期和时间格式化规则。 I/O 操纵符 std::put_time 使用 I/O 流的区域设置的 std::time_put
facet 来生成 std::tm 对象的文本表示。
继承图
如果标准库不保证提供 std::time_put
特化(见下文),则其 put() 和 do_put() 的行为不保证如指定。
内容 |
[编辑] 特化
标准库保证提供以下特化(它们被任何区域设置对象要求实现)
定义于头文件
<locale> | |
std::time_put<char> | 创建日期和时间的窄字符串表示 |
std::time_put<wchar_t> | 创建日期和时间的宽字符串表示 |
此外,标准库还保证提供满足以下类型要求的每个特化
-
CharT
是 char 和 wchar_t 之一,并且 -
OutputIt
必须满足 LegacyOutputIterator 的要求。
[编辑] 嵌套类型
类型 | 定义 |
char_type
|
CharT
|
iter_type
|
OutputIt
|
[编辑] 数据成员
成员 | 描述 |
std::locale::id id [静态] |
facet 的标识符 |
[编辑] 成员函数
构造一个新的 time_put facet(公共成员函数) | |
析构一个 time_put facet(受保护成员函数) | |
调用 do_put (公共成员函数) |
[编辑] 受保护成员函数
[虚函数] |
格式化日期/时间并写入输出流 (虚函数 受保护成员函数) |
[编辑] 示例
运行此代码
#include <codecvt> #include <ctime> #include <iomanip> #include <iostream> int main() { std::time_t t = std::time(nullptr); std::wbuffer_convert<std::codecvt_utf8<wchar_t>> conv(std::cout.rdbuf()); std::wostream out(&conv); out.imbue(std::locale("ja_JP.utf8")); // this I/O manipulator std::put_time uses std::time_put<wchar_t> out << std::put_time(std::localtime(&t), L"%A %c") << '\n'; }
输出
水曜日 2011年11月09日 12時32分05秒
[编辑] 参见
表示具名区域设置的系统提供的 std::time_put (类模板) | |
从输入字符序列解析时间/日期值到 std::tm (类模板) | |
(C++11) |
根据指定的格式格式化并输出日期/时间值 (函数模板) |