LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME
| Localization library | |||||||||||||||||||||||||
| Regular expressions library (C++11) | |||||||||||||||||||||||||
| Formatting library (C++20) | |||||||||||||||||||||||||
| Null-terminated sequence utilities | |||||||||||||||||||||||||
| Byte strings | |||||||||||||||||||||||||
| Multibyte strings | |||||||||||||||||||||||||
| Wide strings | |||||||||||||||||||||||||
| Primitive numeric conversions | |||||||||||||||||||||||||
|
|||||||||||||||||||||||||
| Text encoding identifications | |||||||||||||||||||||||||
|
|||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
定义于头文件
<clocale>
|
||
|
#define LC_ALL /* implementation defined */
|
||
|
#define LC_COLLATE /* implementation defined */
|
||
|
#define LC_CTYPE /* implementation defined */
|
||
|
#define LC_MONETARY /* implementation defined */
|
||
|
#define LC_NUMERIC /* implementation defined */
|
||
|
#define LC_TIME /* implementation defined */
|
||
上述每个宏常量都会展开为具有不同值的整数常量表达式,这些值适合用作 std::setlocale 的第一个参数。
| 常量 | 说明 |
LC_ALL
|
选择整个C区域设置 |
LC_COLLATE
|
选择C区域设置的排序规则类别 |
LC_CTYPE
|
选择C区域设置的字符分类类别 |
LC_MONETARY
|
选择C区域设置的货币格式化类别 |
LC_NUMERIC
|
选择C区域设置的数值格式化类别 |
LC_TIME
|
选择C区域设置的时间格式化类别 |
额外的宏常量,其名称以
LC_
开头后接至少一个大写字母,可能在
<clocale>
中定义。例如,POSIX规范要求包含
LC_MESSAGES
(用于控制
std::perror
和
std::strerror
),ISO/IEC 30112:2014(
2014草案
)额外定义了
LC_IDENTIFICATION
、
LC_XLITERATE
、
LC_NAME
、
LC_ADDRESS
、
LC_TELEPHONE
、
LC_PAPER
、
LC_MEASUREMENT
和
LC_KEYBOARD
,这些常量均受GNU C库支持(除
LC_XLITERATE
外)。
示例
#include <clocale> #include <cstdio> #include <ctime> #include <cwchar> int main() { // C 区域设置将启用 UTF-8 英文环境: std::setlocale(LC_ALL, "en_US.UTF-8"); // 小数点将采用德语格式: std::setlocale(LC_NUMERIC, "de_DE.UTF-8"); // 日期时间格式将采用日语格式: std::setlocale(LC_TIME, "ja_JP.UTF-8"); wchar_t str[100]; std::time_t t = std::time(nullptr); std::wcsftime(str, 100, L"%A %c", std::localtime(&t)); std::wprintf(L"Number: %.2f\nDate: %Ls\n", 3.14, str); }
输出:
Number: 3,14 Date: 日曜日 2022年11月06日 17時55分10秒
参见
|
获取并设置当前C语言区域设置
(函数) |
|
|
封装文化差异的多态facet集合
(类) |
|
|
C文档
关于
locale categories
|
|