std::time_put_byname
来自 cppreference.cn
定义于头文件 <locale> |
||
template< class CharT, |
||
std::time_put_byname
是一个 std::time_put facet,它封装了在其构造时指定的区域设置的时间和日期格式化规则。
目录 |
[编辑] 特化
标准库保证提供满足以下类型要求的每种特化
-
CharT
是 char 和 wchar_t 之一,并且 -
OutputIt
必须满足 LegacyOutputIterator 的要求。
[编辑] 嵌套类型
类型 | 定义 |
char_type
|
CharT
|
iter_type
|
OutputIt
|
[编辑] 成员函数
(构造函数) |
构造一个新的 time_put_byname facet(公有成员函数) |
(析构函数) |
销毁一个 time_put_byname facet(保护成员函数) |
std::time_put_byname::time_put_byname
explicit time_put_byname( const char* name, std::size_t refs = 0 ); |
||
explicit time_put_byname( const std::string& name, std::size_t refs = 0 ); |
(C++11 起) | |
构造一个用于具有 name 的区域设置的新 std::time_put_byname
facet。
refs 用于资源管理:如果 refs == 0,则当最后一个持有它的 std::locale 对象被销毁时,实现会销毁该 facet。否则,该对象不会被销毁。
参数
name | - | 区域设置的名称 |
refs | - | 链接到 facet 的引用计数 |
std::time_put_byname::~time_put_byname
protected: ~time_put_byname(); |
||
销毁 facet。
继承自 std::time_put
[编辑] 数据成员
成员 | 描述 |
std::locale::id id [static] |
facet 的标识符 |
成员函数
调用 do_put ( std::time_put<CharT,OutputIt> 的公有成员函数) |
受保护的成员函数
[虚函数] |
格式化日期/时间并写入输出流 ( std::time_put<CharT,OutputIt> 的虚保护成员函数) |
[编辑] 示例
使用“C”区域设置打印当前时间,其中 time_put
facet 被各种 std::time_put_byname
facet 替换。显示的结果是使用 clang 编译器获得的。
运行此代码
#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(out.getloc(), new std::time_put_byname<wchar_t>("ja_JP.utf8"))); out << std::put_time(std::localtime(&t), L"%A %c") << '\n'; out.imbue(std::locale(out.getloc(), new std::time_put_byname<wchar_t>("ru_RU.utf8"))); out << std::put_time(std::localtime(&t), L"%A %c") << '\n'; out.imbue(std::locale(out.getloc(), new std::time_put_byname<wchar_t>("sv_SE.utf8"))); out << std::put_time(std::localtime(&t), L"%A %c") << '\n'; }
可能的输出
木曜日 2023年10月05日 19時44分51秒 Четверг Чт 05 окт 2023 19:44:51 torsdag tor 5 okt 2023 19:44:51
[编辑] 另请参阅
将 std::tm 的内容格式化为字符序列输出 (类模板) |