std::setlocale

来自cppreference.com

 
 
本地化库
语言环境方面
Original:
Locales and facets
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
locale
字符分类
Original:
Character classification
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
转换
Original:
Conversions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
wstring_convert(C++11)
wbuffer_convert(C++11)
小面类的基类
Original:
Facet category base classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
小面类
Original:
Facet categories
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
特定于语言环境的方面
Original:
Locale-specific facets
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
代码转换方面
Original:
Code conversion facets
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
codecvt_utf8(C++11)
codecvt_utf16(C++11)
codecvt_utf8_utf16(C++11)
codecvt_mode(C++11)
C语言环境
Original:
C locale
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
setlocale
localeconv
lconv
 
Defined in header <clocale>
char* setlocale( int category, const char* locale);
setlocale功能安装指定的系统区域设置或部分作为新的C语言环境。的修改仍然有效,并影响到执行的所有语言环境敏感的C库函​​数,直到下一次调用setlocalelocale是一个空指针,setlocale查询当前的C语言环境,而无需修改
Original:
The setlocale function installs the specified system locale or its portion as the new C locale. The modifications remain in effect and influences the execution of all locale-sensitive C library functions until the next call to setlocale. If locale is a null pointer, setlocale queries the current C locale without modifying it.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目录

[编辑] 参数

category - 宏之一。可能是空的
Original:
locale -
系统特定的区域设置标识符。 ""为用户首选的语言环境或的最小的语言环境。"C"功能安装指定的系统区域设置或修改的部分作为新的C语言环境。留在效果和影响所有语言环境敏感的C库函​​数的执行
Original:
system-specific locale identifier. Can be "" for the user-preferred locale or "C" for the minimal locale
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[编辑] 返回值

指针指向一个狭窄的空结束的字符串识别应用变更后的C语言环境,如果有的话,则返回null指针故障
Original:
Pointer to a narrow null-terminated string identifying the C locale after applying the changes, if any, or null pointer on failure.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[编辑] 注释

在程序启动时,相当于std::setlocale(LC_ALL, "C");任何用户代码运行之前执行.
Original:
During program startup, the equivalent of std::setlocale(LC_ALL, "C"); is executed before any user code is run.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
虽然返回类型是char*,修改所指向的字符是不确定的行为.
Original:
Although the return type is char*, modifying the pointed-to characters is undefined behavior.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
,因为setlocale修改全球状态,影响执行的语言环境相关的功能,它是不确定的行为从一个线程来调用它,而另一个线程正在执行以下功能:std::fprintfstd::isprintstd::iswdigitstd::localeconvstd::tolowerstd::fscanfstd::ispunctstd::iswgraphstd::mblenstd::toupperstd::isalnumstd::isspacestd::iswlowerstd::mbstowcsstd::towlowerstd::isalphastd::isupperstd::iswprintstd::mbtowcstd::towupperstd::isblankstd::iswalnumstd::iswpunctstd::setlocalestd::wcscollstd::iscntrlstd::iswalphastd::iswspacestd::strcollstd::wcstodstd::isdigitstd::iswblankstd::iswupperstd::strerrorstd::wcstombsstd::isgraphstd::iswcntrlstd::iswxdigitstd::strtodstd::wcsxfrmstd::islowerstd::iswctypestd::isxdigit.
Original:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[编辑] 为例

#include <cstdio>
#include <clocale>
#include <ctime>
#include <cwchar>
 
int main()
{
    // the C locale will be UTF-8 enabled English;
    // decimal dot will be German
    // date and time formatting will be Japanese
    std::setlocale(LC_ALL, "en_US.UTF-8");
    std::setlocale(LC_NUMERIC, "de_DE");
    std::setlocale(LC_TIME, "ja_JP");
 
    wchar_t str[100];
    std::time_t t = std::time(NULL);
    std::wcsftime(str, 100, L"%A %c", std::localtime(&t));
    std::wprintf(L"Number: %.2f\nDate: %Ls\n", 3.14, str);
}

Output:

Number: 3,14
Date: 月曜日 2011年12月19日 18時04分40秒

[编辑] 另请参阅

std::setlocale的语言环境类别
Original:
locale categories for std::setlocale
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(宏不变) [edit]
多态的文化差异方面的封装
Original:
set of polymorphic facets that encapsulate cultural differences
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(类) [edit]
C documentation for setlocale