locale.h

locale.h是C程式設計語言標準函式館一個頭檔案,聲明了C語言本地化函式。 這些函式用於在處理多種自然語言的軟體編程設計時,把程式調整到特定的區域設定.。這些區域設定影響到C語言標準庫的輸入/輸出函式。

介紹,所包含的函式,批評,例子,

介紹

locale.hC程式設計語言標準函式館一個頭檔案,聲明了C語言本地化函式. 這些函式用於在處理多種自然語言的軟體編程設計時,把程式調整到特定的區域設定. 這些區域設定影響到C語言標準庫的輸入/輸出函式.

所包含的函式

C語言本地化函式與數據類型定義在locale.h (clocale頭檔案用於C++)
Function
Description
setlocale
設定與讀取當前C locale
localeconv
返回當前locale的貨幣與數值的格式細節

批評

C語言標準中定義的區域設定函式的最大問題是,區域設定狀態是全局的。這意味著一個程式在一個時刻只能有一個locale設定。實現程式同時具有多個locale是非常困難的。
Visual C++運行時刻庫定義了函式_configthreadlocale,可以打開或者關閉執行緒相關區域設定(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, "");
conststruct lconv *const currentlocale = localeconv();
printf("In the current locale, the default currency symbol is: %s\n", currentlocale->currency_symbol);
returnEXIT_SUCCESS;

相關詞條

熱門詞條

聯絡我們