複製鏈接
請複製以下鏈接發送給好友

locale.h

鎖定
locale.h是C程序設計語言標準函數庫一個頭文件,聲明瞭C語言本地化函數。 這些函數用於在處理多種自然語言的軟件編程設計時,把程序調整到特定的區域設置.。這些區域設置影響到C語言標準庫的輸入/輸出函數。
外文名
locale.h
類    別
文件

locale.h基本介紹

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

locale.h所包含的函數

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

locale.h批評

C語言標準中定義的區域設置函數的最大問題是,區域設置狀態是全局的。這意味着一個程序在一個時刻只能有一個locale設置。實現程序同時具有多個locale是非常困難的。
Visual C++運行時刻庫定義了函數_configthreadlocale,可以打開或者關閉線程相關區域設置(thread-specific locale)。另外一個運行時刻庫函數_setmbcp,在線程中創建限於本線程使用的區域設置數據結構。此後,就可以在該線程使用setlocale標準庫函數了。但此種方法僅限於Windows平台。

locale.h例子

#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;