梗概:
配置地域化信息函式
#include <locale.h>
char *setlocale (int category, const char * locale);
描述:
函式種類: 作業系統與環境
內容說明:
本函式用來配置地域的信息,設定當前程式使用的本地化信息。參數 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
返回值
成功:返回相應設定的地域化信息。字元串可能分配在靜態存儲區。
失敗:返回NULL