首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::time_put_byname

Defined in header <locale>

?

?

template< class CharT, class OutputIterator = std::ostreambuf_iterator<CharT> > class time_put_byname : public std::time_put<CharT, OutputIterator>;

?

?

std::time_put_bynamestd::time_putfacet,它封装在构造时指定的区域设置的时间和日期格式规则。

标准库提供了两个专门化。

在标头中定义<locale>

*。

STD:时间[医]放[医]<char,OutputIterator>窄/多字节时间格式

STD:时间[医]放[医]名<wchar[医]T,OutputIterator>宽字符串时间格式

成员类型

Member type

Definition

char_type

CharT

iter_type

OutputIterator

成员函数

(constructor)

constructs a new time_put_byname facet (public member function)

(destructor)

destroys a time_put_byname facet (protected member function)

STD:时间[医]放[医]名称::时间[医]放[医]名名

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 );

?

(since C++11)

构造一个新的std::time_put_byname区域设置的方面name...

refs用于资源管理:如果refs == 0时,该实现破坏了面。std::locale保存它的对象被销毁。否则,该对象不会被销毁。

参数

name

-

the name of the locale

refs

-

the number of references that link to the facet

STD:时间[医]放[医]名称:~时间[医]放[医]名名

protected: ~time_put_byname();

?

?

摧毁了这个面。

继承自STD:时间[医]放

成员对象

Member name

Type

id (static)

std::locale::id

成员函数

put

invokes do_put (public member function of std::time_put)

受保护成员函数

do_put virtual

formats date/time and writes to output stream (virtual protected member function of std::time_put)

此示例使用“C”区域设置与时间一起打印当前时间。[医]用不同的时间代替小面[医]放[医]用名字命名。

二次

代码语言:javascript
复制
#include <iostream>
#include <ctime>
#include <iomanip>
#include <codecvt>
 
int main()
{
    std::time_t t = std::time(NULL);
    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")));
    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'; 
}

二次

可能的产出:

二次

代码语言:javascript
复制
木曜日 2012年08月09日 21時41分02秒
Четверг Чт. 09 авг. 2012 21:41:02
torsdag tor  9 aug 2012 21:41:02

二次

另见

time_put

formats contents of struct std::tm for output as character sequence (class template)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com