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

std::locale

STD:现场

Defined in header
class locale;

类对象std::locale是一组不可变的不可变方面的不可变索引集。C++输入/输出库的每个流对象都与std::locale对象,并使用它的方面对所有数据进行解析和格式化。此外,区域设置对象与每个std::basic_regex对象。locale对象也可以用作谓词,与标准容器和算法执行字符串排序,并可以直接访问以获得或修改它们所持有的方面。

在C++程序中构造的每个区域设置至少包含以下标准方面,但是程序可以定义额外的专门化或全新的方面,并将它们添加到任何现有的locale对象中。

支撑面

*。

STD:校对<char>STD::整理<wchar[医]T>

STD::Ctype<char>STD::Ctype<wchar[医]T>

STD::codecvt<char,char,mbstate[医]t>std::codecvt<char16[医]T,char,mbstate[医]t>std::codecvt<char32[医]T,char,mbstate[医]t>std::codecvt<wchar[医]T,char,mbstate[医]T>

STD:货币量<char>STD::货币化<char,真>std::货币化<wchar[医]T>STD::Moneyypunct<wchar[医]T,真>

STD:钱[医]弄到<char>STD:钱[医]得到<wchar[医]T>

STD:钱[医]放<char>STD:钱[医]放置<wchar[医]T>

性传播疾病:无刺<char>STD::num点t<wchar[医]T>

STD::NUM[医]弄到<char>STD::NUM[医]得到<wchar[医]T>

STD::NUM[医]放<char>STD::NUM[医]放置<wchar[医]T>

STD:时间[医]弄到<char>STD:时间[医]得到<wchar[医]T>

STD:时间[医]放<char>STD:时间[医]放置<wchar[医]T>

STD:信息<char>STD::消息<wchar[医]T>

在内部,区域设置对象被实现为-如果它是指向数组%28索引的引用计数指针。std::locale::id指向方面的引用计数指针%29:复制区域设置只复制一个指针,并增加多个引用计数。为了维护标准的C++库线程安全保证,不同对象上的%28操作总是线程安全的%29,区域设置引用计数和每个方面引用计数都以线程安全的方式更新,类似于std::shared_ptr...

成员类型

idthe facet index type: each facet class must declare or inherit a public static member of this type (class)
facetthe base class for all facet categories: each facet of any category is derived from this type (class)
categoryint (typedef)

成员对象

none statica zero value of type category indicating no facet category (public static member constant)
collate statica bitmask value of type category indicating the collate facet category (public static member constant)
ctype statica bitmask value of type category indicating the ctype facet category (public static member constant)
monetary statica bitmask value of type category indicating the monetary facet category (public static member constant)
numeric statica bitmask value of type category indicating the numeric facet category (public static member constant)
time statica bitmask value of type category indicating the time facet category (public static member constant)
messages statica bitmask value of type category indicating the messages facet category (public static member constant)
all staticcollate | ctype | monetary | numeric | time | messages (public static member constant)

成员函数

(constructor)constructs a new locale (public member function)
(destructor)destructs the locale and the facets whose reference count becomes zero (public member function)
operator=replaces a locale (public member function)
combineconstructs a locale with compile-time identified facet copied from another locale (public member function)
namereturns the name of the locale or "*" if unnamed (public member function)
operator==operator!=equality comparison between locale objects (public member function)
operator()lexicographically compares two strings using this locale's collate facet (public member function)
global staticchanges the global locale (public static member function)
classic staticobtains a reference to the "C" locale (public static member function)

演示区域设置敏感程序%28跨平台%29的典型序言。

二次

#include <iostream> #include <locale> int main() { std::wcout << "User-preferred locale setting is " << std::locale("").name().c_str() << '\n'; // on startup, the global locale is the "C" locale std::wcout << 1000.01 << '\n'; // replace the C++ global locale as well as the C locale with the user-preferred locale std::locale::global(std::locale("") // use the new global locale for future wide character output std::wcout.imbue(std::locale() // output the same number again std::wcout << 1000.01 << '\n'; }

二次

可能的产出:

二次

User-preferred locale setting is en_US.UTF8 1000.01 1,000.01

二次

另见

use_facetobtains a facet from a locale (function template)
has_facetchecks if a locale implements a specific facet (function template)
imbuesets locale (public member function of std::ios_base)
getlocreturns current locale (public member function of std::ios_base)

© cppreference.com

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

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