区域设置Locale

区域设置指你可以用来自定义程序的国家/地区和语言设置。Locale refers to country/region and language settings that you can use to customize your program. 一些与区域设置相关的类别包括日期和货币值的显示格式。Some locale-dependent categories include the display formats for dates and monetary values. 有关详细信息,请参阅区域设置类别For more information, see Locale Categories.

在使用不带 _l 后缀的函数时,可使用 setlocale 函数来更改或查询当前的程序或线程区域设置信息的一部分或全部。Use the setlocale function to change or query some or all of the current program or thread locale information while using functions without the _l suffix. 带有 _l 后缀的函数仅在其执行过程中使用传入的区域设置参数来获取区域设置信息。The functions with the _l suffix will use the locale parameter passed in for their locale information during the execution of that specific function only. 若要创建用于带有 _l 后缀的函数的区域设置,请使用 _create_localeTo create a locale for use with a function with a _l suffix, use _create_locale. 若要释放此区域设置,请使用 _free_localeTo free this locale, use _free_locale. 若要获取当前区域设置,请使用 _get_current_localeTo get the current locale, use _get_current_locale.

使用 _configthreadlocale 可控制是每个线程都有自己的区域设置,还是程序中的所有线程都共享同一区域设置。Use _configthreadlocale to control whether each thread has its own locale, or all threads in a program share the same locale. 有关详细信息,请参阅区域设置和代码页For more information, see Locales and Code Pages.

下表中的函数还有更安全的版本,由 _s(“secure”)后缀指示。More secure versions of the functions in the following table are available, indicated by the _s ("secure") suffix. 有关详细信息,请参阅 CRT 中的安全功能For more information, see Security Features in the CRT.

与区域设置相关的例程Locale-Dependent Routines

例程Routine 使用Use setlocale 类别设置依赖项setlocale category setting dependence
atof、_atof_l、_wtof、_wtof_latof, _atof_l, _wtof, _wtof_l 将字符转换为浮点值Convert character to floating-point value LC_NUMERIC
atoi、_atoi_l、_wtoi、_wtoi_latoi, _atoi_l, _wtoi, _wtoi_l 将字符转换为整数值Convert character to integer value LC_NUMERIC
_atoi64、_atoi64_l、_wtoi64、_wtoi64_l_atoi64, _atoi64_l, _wtoi64, _wtoi64_l 将字符转换为 64 位整数值Convert character to 64-bit integer value LC_NUMERIC
ato、_atol_l、_wtol、_wtol_latol, _atol_l, _wtol, _wtol_l 将字符转换为长值Convert character to long value LC_NUMERIC
_atodbl、_atodbl_l、_atoldbl、_atoldbl_l、_atoflt、_atoflt_l_atodbl, _atodbl_l, _atoldbl, _atoldbl_l, _atoflt, _atoflt_l 将字符转换为长双精度值Convert character to double-long value LC_NUMERIC
is 例程is Routines 针对特定条件测试给定整数。Test given integer for particular condition. LC_CTYPE
isleadbyte、_isleadbyte_lisleadbyte, _isleadbyte_l 测试前导字节Test for lead byte LC_CTYPE
localeconvlocaleconv 读取合适的值来格式化数字量Read appropriate values for formatting numeric quantities LC_MONETARY, LC_NUMERIC
MB_CUR_MAXMB_CUR_MAX 当前区域设置中任何多字节字符的最大长度(字节数)(STDLIB.H 中定义的宏)Maximum length in bytes of any multibyte character in current locale (macro defined in STDLIB.H) LC_CTYPE
_mbccpy、_mbccpy_l_mbccpy_s、_mbccpy_s_l_mbccpy, _mbccpy_l,_mbccpy_s, _mbccpy_s_l 复制一个多字节字符Copy one multibyte character LC_CTYPE
_mbclen、mblen、_mblen_l_mbclen, mblen, _mblen_l 验证并返回多字节字符中的字节数Validate and return number of bytes in multibyte character LC_CTYPE
strlen、wcslen、_mbslen、_mbslen_l、_mbstrlen、_mbstrlen_lstrlen, wcslen, _mbslen, _mbslen_l, _mbstrlen, _mbstrlen_l 对于多字节字符串:验证字符串中的每个字符;返回字符串的长度For multibyte-character strings: validate each character in string; return string length LC_CTYPE
mbstowcs、_mbstowcs_lmbstowcs_、_mbstowcs_s_lmbstowcs, _mbstowcs_l,mbstowcs_s, _mbstowcs_s_l 将多字节字符序列转换为对应的宽字符序列Convert sequence of multibyte characters to corresponding sequence of wide characters LC_CTYPE
mbtowc、_mbtowc_lmbtowc, _mbtowc_l 将多字节字符转换为对应的宽字符Convert multibyte character to corresponding wide character LC_CTYPE
printf 函数printf functions 写入格式化的输出Write formatted output LC_NUMERIC(确定基数字符输出)LC_NUMERIC (determines radix character output)
scanf 函数scanf functions 读取格式化的输入Read formatted input LC_NUMERIC (确定基数字符标识)LC_NUMERIC (determines radix character recognition)
setlocale、_wsetlocalesetlocale, _wsetlocale 选择程序的区域设置Select locale for program 不适用Not applicable
strcoll、wcscoll、_mbscoll、_strcoll_l、_wcscoll_l、_mbscoll_lstrcoll, wcscoll, _mbscoll, _strcoll_l, _wcscoll_l, _mbscoll_l 比较两个字符串的字符Compare characters of two strings LC_COLLATE
_stricmp、_wcsicmp、_mbsicmp、_stricmp_l、_wcsicmp_l、_mbsicmp_l_stricmp, _wcsicmp, _mbsicmp, _stricmp_l, _wcsicmp_l, _mbsicmp_l 比较两个字符串(不考虑大小写)Compare two strings without regard to case LC_CTYPE
_stricoll、_wcsicoll、_mbsicoll、_stricoll_l、_wcsicoll_l、_mbsicoll_l_stricoll, _wcsicoll, _mbsicoll, _stricoll_l, _wcsicoll_l, _mbsicoll_l 比较两个字符串的字符(不区分大小写)Compare characters of two strings (case insensitive) LC_COLLATE
_strncoll、_wcsncoll、_mbsncoll、_strncoll_l、_wcsncoll_l、_mbsncoll_l_strncoll, _wcsncoll, _mbsncoll, _strncoll_l, _wcsncoll_l, _mbsncoll_l 比较两个字符串的第一个 n 字符Compare first n characters of two strings LC_COLLATE
_strnicmp、_wcsnicmp、_mbsnicmp、_strnicmp_l、_wcsnicmp_l、_mbsnicmp_l_strnicmp, _wcsnicmp, _mbsnicmp, _strnicmp_l, _wcsnicmp_l, _mbsnicmp_l 比较两个字符串的字符(不考虑大小写)。Compare characters of two strings without regard to case. LC_CTYPE
_strnicoll、_wcsnicoll、_mbsnicoll、_strnicoll_l、_wcsnicoll_l、_mbsnicoll_l_strnicoll, _wcsnicoll, _mbsnicoll, _strnicoll_l, _wcsnicoll_l, _mbsnicoll_l 比较两个字符串的第一个 n 字符(不区分大小写)Compare first n characters of two strings (case insensitive) LC_COLLATE
strftime、wcsftime、_strftime_l、_wcsftime_lstrftime, wcsftime, _strftime_l, _wcsftime_l 根据提供的 format 参数设置日期和时间值的格式Format date and time value according to supplied format argument LC_TIME
_strlwr、_wcslwr、_mbslwr、_strlwr_l、_wcslwr_l、_mbslwr_l_strlwr_s、_strlwr_s_l、_mbslwr_s、_mbslwr_s_l、_wcslwr_s、_wcslwr_s_l_strlwr, _wcslwr, _mbslwr, _strlwr_l, _wcslwr_l, _mbslwr_l,_strlwr_s, _strlwr_s_l, _mbslwr_s, _mbslwr_s_l, _wcslwr_s, _wcslwr_s_l 将给定字符串中的每个大写字母就地转换为小写字母Convert, in place, each uppercase letter in given string to lowercase LC_CTYPE
strtod、_strtod_l、wcstod、_wcstod_lstrtod, _strtod_l, wcstod, _wcstod_l 将字符串转换为 doubleConvert character string to double value LC_NUMERIC (确定基数字符标识)LC_NUMERIC (determines radix character recognition)
strtol、wcstol、_strtol_l、_wcstol_lstrtol, wcstol, _strtol_l, _wcstol_l 将字符串转换为 longConvert character string to long value LC_NUMERIC (确定基数字符标识)LC_NUMERIC (determines radix character recognition)
strtoul、_strtoul_l、wcstoul、_wcstoul_lstrtoul, _strtoul_l, wcstoul, _wcstoul_l 将字符串转换为无符号长值Convert character string to unsigned long value LC_NUMERIC (确定基数字符标识)LC_NUMERIC (determines radix character recognition)
_strupr、_strupr_l、_mbsupr、_mbsupr_l、_wcsupr_l、_wcsupr_strupr_s、_strupr_s_l、_mbsupr_s、_mbsupr_s_l、_wcsupr_s、_wcsupr_s_l_strupr, _strupr_l, _mbsupr, _mbsupr_l, _wcsupr_l, _wcsupr,_strupr_s, _strupr_s_l, _mbsupr_s, _mbsupr_s_l, _wcsupr_s, _wcsupr_s_l 将字符串的每个小写字母就地转换为大写字母Convert, in place, each lowercase letter in string to uppercase LC_CTYPE
strxfrm、wcsxfrm、_strxfrm_l、_wcsxfrm_lstrxfrm, wcsxfrm, _strxfrm_l, _wcsxfrm_l 根据区域设置将字符串转换为排序格式Transform string into collated form according to locale LC_COLLATE
tolower、_tolower、towlower、_tolower_l、_towlower_l_mbctolower、_mbctolower_l、_mbctoupper、_mbctoupper_ltolower, _tolower, towlower, _tolower_l, _towlower_l,_mbctolower, _mbctolower_l, _mbctoupper, _mbctoupper_l 将给定的字符转换为相应的小写字母Convert given character to corresponding lowercase character LC_CTYPE
toupper、_toupper、towupper、_toupper_l、_towupper_l_mbctolower、_mbctolower_l、_mbctoupper、_mbctoupper_ltoupper, _toupper, towupper, _toupper_l, _towupper_l,_mbctolower, _mbctolower_l, _mbctoupper, _mbctoupper_l 将给定的字符转换为相应的大写字母Convert given character to corresponding uppercase letter LC_CTYPE
wcstombs、_wcstombs_lwcstombs_s、_wcstombs_s_lwcstombs, _wcstombs_l,wcstombs_s, _wcstombs_s_l 将宽字符序列转换为相应的多字节字符序列Convert sequence of wide characters to corresponding sequence of multibyte characters LC_CTYPE
wctomb、_wctomb_lwctomb_s、_wctomb_s_lwctomb, _wctomb_l,wctomb_s, _wctomb_s_l 将宽字符转换为相应的多字节字符Convert wide character to corresponding multibyte character LC_CTYPE

备注

对于多字节例程,多字节代码页必须与使用 setlocale 设置的区域设置等效。For multibyte routines, the multibyte code page must be equivalent to the locale set with setlocale. 带有 _MB_CP_LOCALE 参数的 _setmbcp 使多字节代码页与 setlocale 代码页相同。_setmbcp, with an argument of _MB_CP_LOCALE makes the multibyte code page the same as the setlocale code page.

另请参阅See Also

国际化 Internationalization
按类别分的运行时例程Run-Time Routines by Category