c++11 标准模板(STL)本地化库 - 平面类别 (std::time_put_byname)表示系统提供的具名本地环境的 std::time_put

本文主要是介绍c++11 标准模板(STL)本地化库 - 平面类别 (std::time_put_byname)表示系统提供的具名本地环境的 std::time_put,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

本地化库

本地环境设施包含字符分类和字符串校对、数值、货币及日期/时间格式化和分析,以及消息取得的国际化支持。本地环境设置控制流 I/O 、正则表达式库和 C++ 标准库的其他组件的行为。

平面类别

表示系统提供的具名本地环境的 std::time_put

std::time_put_byname

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

std::time_put_byname 是 std::time_put 平面,封装在其构造时指定的 locale 的日期和时间格式化规则。

标准库提供二个特化

定义于头文件 <locale>

std::time_put_byname<char, OutputIterator>窄/多字节时间格式化
std::time_put_byname<wchar_t, OutputIterator>宽字符串时间格式化

成员类型

成员类型定义
char_typeCharT
iter_typeOutputIterator

成员函数

(构造函数)

构造新的 time_put_byname 平面
(公开成员函数)

(析构函数)

析构 time_put_byname 平面
(受保护成员函数)

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 平面。

refs 用于资源管理:在销毁最后一个保有平面的 std::locale 对象时,若 refs == 0 ,则实现销毁平面对象。否则,不销毁对象。

参数

name-本地环境的名称
refs-链接到该平面的引用数

std::time_put_byname::~time_put_byname

protected:
~time_put_byname();

销毁平面。

继承自 std::time_put

成员对象

成员名类型
id [静态]std::locale::id

成员函数

put

调用 do_put
(std::time_put<CharT,OutputIt> 的公开成员函数)

受保护成员函数

do_put

[虚]

格式化日期/时间并写入输出流
(std::time_put<CharT,OutputIt> 的虚受保护成员函数)

调用示例 windows

#include <iostream>
#include <sstream>
#include <locale>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <iterator>
#include <Windows.h>std::vector<std::wstring> locals;BOOL CALLBACK MyFuncLocaleEx(LPWSTR pStr, DWORD dwFlags, LPARAM lparam)
{locals.push_back(pStr);return TRUE;
}std::string stows(const std::wstring& ws)
{std::string curLocale = setlocale(LC_ALL, NULL); // curLocale = "C";setlocale(LC_ALL, "chs");const wchar_t* _Source = ws.c_str();size_t _Dsize = 2 * ws.size() + 1;char *_Dest = new char[_Dsize];memset(_Dest, 0, _Dsize);wcstombs(_Dest, _Source, _Dsize);std::string result = _Dest;delete[]_Dest;setlocale(LC_ALL, curLocale.c_str());return result;
}void try_time_put(const std::tm* tm, const std::string& strfmt)
{std::cout.imbue(std::locale());std::cout << "In the locale '" << std::cout.getloc().name() << "' : '";std::use_facet<std::time_put_byname<char>>(std::cout.getloc()).put({std::cout}, std::cout, ' ', tm, &strfmt[0], &strfmt[0] + strfmt.size());std::cout << std::endl;
}int main()
{EnumSystemLocalesEx(MyFuncLocaleEx, LOCALE_ALTERNATE_SORTS, NULL, NULL);for (std::vector<std::wstring>::const_iterator str = locals.begin();str != locals.end(); ++str){std::time_t time_t = std::time(NULL);std::tm tm = *std::localtime(&time_t);std::string strfmt = "%c";std::cout << "Using the format string '" << strfmt<< "' to format the time: " << std::ctime(&time_t);std::locale::global(std::locale(stows(*str)));try_time_put(&tm, strfmt);}return 0;
}

输出

Using the format string '%c' to format the time: Sun May 19 20:30:56 2024
In the locale 'de-DE_phoneb' : '19.05.2024 20:30:56
Using the format string '%c' to format the time: Sun May 19 20:30:57 2024
In the locale 'es-ES_tradnl' : '19/05/2024 20:30:57
Using the format string '%c' to format the time: Sun May 19 20:30:57 2024
In the locale 'hu-HU_technl' : '2024. 05. 19. 20:30:57
Using the format string '%c' to format the time: Sun May 19 20:30:57 2024
In the locale 'ja-JP_radstr' : '2024/05/19 20:30:57
Using the format string '%c' to format the time: Sun May 19 20:30:57 2024
In the locale 'ka-GE_modern' : '19.05.2024 20:30:57
Using the format string '%c' to format the time: Sun May 19 20:30:57 2024
In the locale 'x-IV_mathan' : '05/19/2024 20:30:57
Using the format string '%c' to format the time: Sun May 19 20:30:57 2024
In the locale 'zh-CN_phoneb' : '2024/5/19 20:30:57
Using the format string '%c' to format the time: Sun May 19 20:30:57 2024
In the locale 'zh-CN_stroke' : '2024/5/19 20:30:57
Using the format string '%c' to format the time: Sun May 19 20:30:57 2024
In the locale 'zh-HK_radstr' : '19/5/2024 20:30:57
Using the format string '%c' to format the time: Sun May 19 20:30:57 2024
In the locale 'zh-MO_radstr' : '19/5/2024 20:30:57
Using the format string '%c' to format the time: Sun May 19 20:30:57 2024
In the locale 'zh-MO_stroke' : '19/5/2024 20:30:57
Using the format string '%c' to format the time: Sun May 19 20:30:57 2024
In the locale 'zh-SG_phoneb' : '19/5/2024 下午 8:30:
Using the format string '%c' to format the time: Sun May 19 20:30:57 2024
In the locale 'zh-SG_stroke' : '19/5/2024 下午 8:30:
Using the format string '%c' to format the time: Sun May 19 20:30:57 2024
In the locale 'zh-TW_pronun' : '2024/5/19 下午 08:30:
Using the format string '%c' to format the time: Sun May 19 20:30:57 2024
In the locale 'zh-TW_radstr' : '2024/5/19 下午 08:30:

这篇关于c++11 标准模板(STL)本地化库 - 平面类别 (std::time_put_byname)表示系统提供的具名本地环境的 std::time_put的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/998166

相关文章

不懂推荐算法也能设计推荐系统

本文以商业化应用推荐为例,告诉我们不懂推荐算法的产品,也能从产品侧出发, 设计出一款不错的推荐系统。 相信很多新手产品,看到算法二字,多是懵圈的。 什么排序算法、最短路径等都是相对传统的算法(注:传统是指科班出身的产品都会接触过)。但对于推荐算法,多数产品对着网上搜到的资源,都会无从下手。特别当某些推荐算法 和 “AI”扯上关系后,更是加大了理解的难度。 但,不了解推荐算法,就无法做推荐系

基于人工智能的图像分类系统

目录 引言项目背景环境准备 硬件要求软件安装与配置系统设计 系统架构关键技术代码示例 数据预处理模型训练模型预测应用场景结论 1. 引言 图像分类是计算机视觉中的一个重要任务,目标是自动识别图像中的对象类别。通过卷积神经网络(CNN)等深度学习技术,我们可以构建高效的图像分类系统,广泛应用于自动驾驶、医疗影像诊断、监控分析等领域。本文将介绍如何构建一个基于人工智能的图像分类系统,包括环境

水位雨量在线监测系统概述及应用介绍

在当今社会,随着科技的飞速发展,各种智能监测系统已成为保障公共安全、促进资源管理和环境保护的重要工具。其中,水位雨量在线监测系统作为自然灾害预警、水资源管理及水利工程运行的关键技术,其重要性不言而喻。 一、水位雨量在线监测系统的基本原理 水位雨量在线监测系统主要由数据采集单元、数据传输网络、数据处理中心及用户终端四大部分构成,形成了一个完整的闭环系统。 数据采集单元:这是系统的“眼睛”,

【C++ Primer Plus习题】13.4

大家好,这里是国中之林! ❥前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到网站。有兴趣的可以点点进去看看← 问题: 解答: main.cpp #include <iostream>#include "port.h"int main() {Port p1;Port p2("Abc", "Bcc", 30);std::cout <<

C++包装器

包装器 在 C++ 中,“包装器”通常指的是一种设计模式或编程技巧,用于封装其他代码或对象,使其更易于使用、管理或扩展。包装器的概念在编程中非常普遍,可以用于函数、类、库等多个方面。下面是几个常见的 “包装器” 类型: 1. 函数包装器 函数包装器用于封装一个或多个函数,使其接口更统一或更便于调用。例如,std::function 是一个通用的函数包装器,它可以存储任意可调用对象(函数、函数

poj3468(线段树成段更新模板题)

题意:包括两个操作:1、将[a.b]上的数字加上v;2、查询区间[a,b]上的和 下面的介绍是下解题思路: 首先介绍  lazy-tag思想:用一个变量记录每一个线段树节点的变化值,当这部分线段的一致性被破坏我们就将这个变化值传递给子区间,大大增加了线段树的效率。 比如现在需要对[a,b]区间值进行加c操作,那么就从根节点[1,n]开始调用update函数进行操作,如果刚好执行到一个子节点,

嵌入式QT开发:构建高效智能的嵌入式系统

摘要: 本文深入探讨了嵌入式 QT 相关的各个方面。从 QT 框架的基础架构和核心概念出发,详细阐述了其在嵌入式环境中的优势与特点。文中分析了嵌入式 QT 的开发环境搭建过程,包括交叉编译工具链的配置等关键步骤。进一步探讨了嵌入式 QT 的界面设计与开发,涵盖了从基本控件的使用到复杂界面布局的构建。同时也深入研究了信号与槽机制在嵌入式系统中的应用,以及嵌入式 QT 与硬件设备的交互,包括输入输出设

C++11第三弹:lambda表达式 | 新的类功能 | 模板的可变参数

🌈个人主页: 南桥几晴秋 🌈C++专栏: 南桥谈C++ 🌈C语言专栏: C语言学习系列 🌈Linux学习专栏: 南桥谈Linux 🌈数据结构学习专栏: 数据结构杂谈 🌈数据库学习专栏: 南桥谈MySQL 🌈Qt学习专栏: 南桥谈Qt 🌈菜鸡代码练习: 练习随想记录 🌈git学习: 南桥谈Git 🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈�

JAVA智听未来一站式有声阅读平台听书系统小程序源码

智听未来,一站式有声阅读平台听书系统 🌟&nbsp;开篇:遇见未来,从“智听”开始 在这个快节奏的时代,你是否渴望在忙碌的间隙,找到一片属于自己的宁静角落?是否梦想着能随时随地,沉浸在知识的海洋,或是故事的奇幻世界里?今天,就让我带你一起探索“智听未来”——这一站式有声阅读平台听书系统,它正悄悄改变着我们的阅读方式,让未来触手可及! 📚&nbsp;第一站:海量资源,应有尽有 走进“智听

阿里开源语音识别SenseVoiceWindows环境部署

SenseVoice介绍 SenseVoice 专注于高精度多语言语音识别、情感辨识和音频事件检测多语言识别: 采用超过 40 万小时数据训练,支持超过 50 种语言,识别效果上优于 Whisper 模型。富文本识别:具备优秀的情感识别,能够在测试数据上达到和超过目前最佳情感识别模型的效果。支持声音事件检测能力,支持音乐、掌声、笑声、哭声、咳嗽、喷嚏等多种常见人机交互事件进行检测。高效推