在线文档教程
C++
本土化 | Localizations

std::locale::locale

STD::locale::locale

Defined in header
locale((1)
locale( const locale& other (2)
explicit locale( const char* std_name (3)
explicit locale( const std::string& std_name (4)(since C++11)
locale( const locale& other, const char* std_name, category cat (5)
locale( const locale& other, const std::string& std_name, category cat (6)(since C++11)
template< class Facet > locale( const locale& other, Facet* f (7)
locale( const locale& other, const locale& one, category cat (8)

构造一个新的区域设置对象。

1%29默认构造函数。构造全局C++区域设置的副本,这是最近用作std::locale::global或一份std::locale::classic如果没有呼叫std::locale::global已经制作好了。

2%29复制构造函数。构造other...

3-4%29构造系统区域设置的副本。std_name%28,如“C”、“POSIX”或“EN”[医]“us.utf-8”或“English”[医]如果操作系统支持此区域设置,则US.1251“%29”。以这种方式构造的区域设置有一个名称。

5-6%29构造othercat参数,这些参数是从由其标识的系统区域设置复制的。std_name.以这种方式构造的区域设置有一个名称当且仅当other有个名字。

7%29构造other除了类型的面Facet%28通常是从参数%29的类型推断的,该参数是从参数安装的facet.如果facetNULL,构造的区域设置是other.以这种方式构造的地区没有名称。

8%29构造othercat参数,这些参数是从one.如果两者都是otherone有名称,则结果区域设置也有名称。

参数

other-another locale to copy
std_name-name of the system locale to use
f-pointer to a facet to merge with other
cat-the locale category used to identify the facets to merge with other
one-another locale to take facets from

例外

1,2%29

(none)(until C++11)
noexcept specification: noexcept(since C++11)

3.5%29std::runtime_error如果操作系统没有名为std_name或者如果std_nameNULL...

4,6%29std::runtime_error如果操作系统没有名为std_name...

7,8%29%28无29

注记

重载7通常用第二个参数调用,f,直接从新表达式获得:区域设置负责调用匹配。delete从它自己的破坏者那里。

二次

#include <iostream> #include <locale> #include <codecvt> int main() { std::locale l1; // l1 is a copy of the classic "C" locale std::locale l2("en_US.UTF-8" // l2 is a unicode locale std::locale l3(l1, l2, std::locale::ctype // l3 is "C" except for ctype, which is unicode std::locale l4(l1, new std::codecvt_utf8<wchar_t> // l4 is "C" except for codecvt std::cout << "Locale names:\nl1: " << l1.name() << "\nl2: " << l2.name() << "\nl3: " << l3.name() << "\nl4: " << l4.name() << '\n'; }

二次

产出:

二次

Locale names: l1: C l2: en_US.UTF-8 l3: LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=C;LC_PAPER=C;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C;LC_IDENTIFICATION=C l4: *

二次

另见

(destructor)destructs the locale and the facets whose reference count becomes zero (public member function)

© cppreference.com

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

http://en.cppreference.com/w/cpp/locale/locale/locale