建立地區設定物件。
語法
_locale_t _create_locale(
int category,
const char *locale
);
_locale_t _wcreate_locale(
int category,
const wchar_t *locale
);
參數
category
類別。
locale
地區設定指定名稱。
傳回值
如果提供有效的 locale 和 category ,函式會將指定的地區設定當做 _locale_t 對象傳回。 程式的目前地區設定不會變更。
備註
_create_locale 函式可讓您建立代表某些特定地區設定的物件,以供許多 CRT 函式 (尾碼為 _l 的函式) 的特定地區設定版本使用。 此行為類似於 setlocale,但不會將指定的地區設定套用至目前的環境,而是將設定儲存在傳回的 _locale_t 結構中。 _locale_t當不再需要結構時,應該使用 _free_locale 釋放結構。
_wcreate_locale 是寬字元版本的 _create_locale; locale 的 _wcreate_locale 引數是寬字元字串。 否則,_wcreate_locale 和 _create_locale 的行為即會相同。
category 引數會指定特定地區設定行為中受影響的部分。 用於 category 的旗標及其影響之程式的各個部分,如下表所示:
category 旗標 |
Affects |
|---|---|
LC_ALL |
所有分類,如下所示。 |
LC_COLLATE |
strcoll、_stricoll、wcscoll、_wcsicoll、strxfrm、_strncoll、_strnicoll、_wcsncoll、_wcsnicoll 以及 wcsxfrm 函式。 |
LC_CTYPE |
字元處理函式 (除了 isdigit、isxdigit、mbstowcs 和 mbtowc,這些不會受到影響)。 |
LC_MONETARY |
localeconv 函式傳回的貨幣格式資訊。 |
LC_NUMERIC |
由 printf 所傳回適用於格式化輸出常式 (如 localeconv)、資料轉換常式和非貨幣格式化資訊的小數點字元。 除了小數點字元之外, LC_NUMERIC 還設定 所傳 localeconv回的千位分隔符和群組控制字串。 |
LC_TIME |
strftime 和 wcsftime 函式。 |
這個函式會驗證 category 和 locale 參數。 如果類別參數不是上表指定的其中一個值,或 如果 locale 是 NULL,則函式會傳 NULL回 。
locale 引數是指向會指定地區設定的字串指標。 如需自變數格式 locale 的詳細資訊,請參閱 地區設定名稱、語言和國家/地區字串。
自 locale 變數可以採用數種值:地區設定名稱、語言字串、語言字串和國家/地區代碼、代碼頁,或語言字串、國家/地區代碼和代碼頁的組合。 一組可用的地區設定名稱、語言、國家/地區代碼和代碼頁,包含 Windows NLS API 支援的所有專案。 地區設定名稱 _create_locale 集支援的說明是 地區設定名稱、語言和國家/地區字串。 所 _create_locale 支援的語言和國家/地區字串集合會列在 語言字串 和國家 /地區字串中。
如需地區設定的詳細資訊,請參閱 setlocale。 _wsetlocale
已取代此函式的舊名稱 __create_locale (含兩個前置底線)。
根據預設,此函式的全域狀態會限定於應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態。
需求
| 常式 | 必要的標頭 |
|---|---|
_create_locale |
<locale.h> |
_wcreate_locale |
<locale.h> 或 <wchar.h> |
如需相容性詳細資訊,請參閱相容性。
範例
// crt_create_locale.c
// Sets the current locale to "de-CH" using the
// setlocale function and demonstrates its effect on the strftime
// function.
#include <stdio.h>
#include <locale.h>
#include <time.h>
int main(void)
{
time_t ltime;
struct tm thetime;
unsigned char str[100];
_locale_t locale;
// Create a locale object representing the German (Switzerland) locale
locale = _create_locale(LC_ALL, "de-CH");
time (<ime);
_gmtime64_s(&thetime, <ime);
// %#x is the long date representation, appropriate to
// the current locale
if (!_strftime_l((char *)str, 100, "%#x",
(const struct tm *)&thetime, locale))
{
printf("_strftime_l failed!\n");
}
else
{
printf("In de-CH locale, _strftime_l returns '%s'\n", str);
}
_free_locale(locale);
// Create a locale object representing the default C locale
locale = _create_locale(LC_ALL, "C");
time(<ime);
_gmtime64_s(&thetime, <ime);
if (!_strftime_l((char *)str, 100, "%#x",
(const struct tm *)&thetime, locale))
{
printf("_strftime_l failed!\n");
}
else
{
printf("In 'C' locale, _strftime_l returns '%s'\n", str);
}
_free_locale(locale);
}
In de-CH locale, _strftime_l returns 'Samstag, 9. Februar 2002'
In 'C' locale, _strftime_l returns 'Saturday, February 09, 2002'
另請參閱
地區設定名稱、語言和國家/地區字串
語言字串
國家/地區字串
_free_locale
_configthreadlocale
setlocale
地區設定
localeconv
_mbclen、 、 mblen_mblen_l
strlen、、wcslen_mbslen、_mbslen_l、、_mbstrlen、_mbstrlen_l
mbstowcs, _mbstowcs_l
mbtowc, _mbtowc_l
_setmbcp
setlocale, _wsetlocale
strcoll 函數
strftime、 、 wcsftime、 _strftime_l_wcsftime_l
strxfrm、 、 wcsxfrm、 _strxfrm_l_wcsxfrm_l
wcstombs, _wcstombs_l
wctomb, _wctomb_l