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

Setlocale

鎖定
Setlocale是一個計算機函數,功能是用來配置地域的信息,設置當前程序使用的本地化信息。若 locale 為零(NULL),則不會改變地域化配置,返回當前的地域值,若系統尚未實作則返回 false。
外文名
Setlocale
函數種類
操作系統與環境
類    型
數據
領    域
程序

目錄

Setlocale梗概

配置地域化信息函數
#include <locale.h>
char *setlocale (int category, const char * locale); [1] 

Setlocale描述

函數種類: 操作系統與環境
內容説明:
本函數用來配置地域的信息,設置當前程序使用的本地化信息。參數 category 有下列的選擇:
LC_ALL 包括下面的全部選項都要。 LC_COLLATE 配置字符串比較,PHP 尚未實作出來本項。 LC_CTYPE 配置字符類別及轉換。例如全變大寫 strtoupper()。 LC_MONETARY 配置金融貨幣,PHP 尚未實作。 LC_NUMERIC 配置小數點後的位數。 LC_TIME 配置時間日期格式,與 strftime() 合用。 而參數 locale 若是空字符串 "",則會使用系統環境變量的 locale 。若 locale 為零(NULL),則不會改變地域化配置,返回當前的地域值,若系統尚未實作則返回 false。
Locales contain information on how to interpret and perform certain input/output and transformation operations taking into consideration location and language specific settings.
Most running environments have certain locale information set according to the user preferences or localization. But, independently of this system locale, on start, all C programs have the "C" locale set, which is a rather neutral locale with minimal locale information that allows the result of programs to be predictable. In order to use the default locale set in the environment, this function can be called with "" as the localeparameter.
The locale set on start is the same as setlocale(LC_ALL,"C") would set.
The entire default locale can be set by calling setlocale(LC_ALL,"");
C程序開始的時候的設置和 setlocale(LC_ALL,"C")相同
使用系統默認的設置調用setlocale(LC_ALL,"");
The parts of the current locale affected by a call to this function are specified by parameter category.
若想顯示中文"我愛你",則要包含#include <locale.h> 加一下代碼:
wchar_t s[]={ 25105, 29233 ,20320 ,0};
setlocale( LC_ALL, "" );
printf("%ls",s);//注意是ls

Setlocale返回值

成功:返回相應設置的地域化信息。字符串可能分配在靜態存儲區。
失敗:返回NULL
參考資料