Locale.h
来自维基百科,自由的百科全书
locale.h是C程式設計語言標準函式庫的一個標頭檔,聲明了C語言在地化函式。[1][2] 這些函式用於在處理多種自然語言的軟體編程設計時,把程式調整到特定的區域設定. 這些區域設定影響到C語言標準庫的輸入/輸出函式.
所包含的函式
C語言在地化函式與資料類型定義在locale.h (clocale標頭檔用於C++).[3]
Function | Description |
---|---|
setlocale
|
設定與讀取當前C locale |
localeconv
|
返回當前locale的貨幣與數值的格式細節 |
批評
C語言標準中定義的區域設定函式的最大問題是,區域設定狀態是全域的。這意味著一個程式在一個時刻只能有一個locale設定。實現程式同時具有多個locale是非常困難的。[4]
Visual C++執行時刻庫定義了函式_configthreadlocale
[5],可以打開或者關閉執行緒相關區域設定(thread-specific locale)。另外一個執行時刻庫函式_setmbcp
,線上程中建立限於本執行緒使用的區域設定資料結構。此後,就可以在該執行緒使用setlocale標準庫函式了。但此種方法僅限於Windows平台。
例子
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
int main(void)
{
/* Locale is set to "C" before this. This call sets it
to the "current locale" by reading environment variables: */
setlocale(LC_ALL, "");
const struct lconv * const currentlocale = localeconv();
printf("In the current locale, the default currency symbol is: %s\n",
currentlocale->currency_symbol);
return EXIT_SUCCESS;
}
參考文獻
Wikiwand - on
Seamless Wikipedia browsing. On steroids.