LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME
來自 cppreference.com
定義於標頭檔案 <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 區域設定的時間格式類別 |
在 <clocale> 中可能定義了其他宏常量,其名稱以 LC_
開頭,後跟至少一個大寫字母。例如,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() { // the C locale will be the UTF-8 enabled English: std::setlocale(LC_ALL, "en_US.UTF-8"); // decimal dot will be German: std::setlocale(LC_NUMERIC, "de_DE.UTF-8"); // date/time formatting will be Japanese: 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 區域設定 (函式) | |
封裝文化差異的多型刻面集 (類) | |
C 文件,關於 區域設定類別
|