setlocale
来自cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| Defined in header <locale.h>
|
||
| char* setlocale( int category, const char* locale); |
||
setlocale功能安装指定的系统区域设置或部分作为新的C语言环境。的修改仍然有效,并影响到执行的所有语言环境敏感的C库函数,直到下一次调用setlocale。 locale是一个空指针,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.
You can help to correct and verify the translation. Click here for instructions.
目录 |
[编辑] 参数
| category | - | 宏之一。可能是空的 Original: locale category identifier, one of the LC_xxx Original: LC_xxx The text has been machine-translated via [http://translate.google.com Google Translate]. You can help to correct and verify the translation. Click [http://en.cppreference.com/w/Cppreference:MachineTranslations here] for instructions. The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| 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. |
[编辑] 返回值
指针到一个狭窄的null结尾的字符串识别应用变更后的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.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 注释
在程序启动时,相当于setlocale(LC_ALL, "C");任何用户代码运行之前执行.
Original:
During program startup, the equivalent of 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.
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.
You can help to correct and verify the translation. Click here for instructions.
,因为
setlocale修改全球状态,影响执行的语言环境相关的功能,它是不确定的行为从一个线程来调用它,而另一个线程正在执行以下功能:fprintf,isprint,iswdigit,localeconv,tolower,fscanf,ispunct,iswgraph,mblen, toupper,isalnum,isspace,iswlower,mbstowcs,towlower,isalpha,isupper,iswprint,mbtowc,towupper,isblank,iswalnum,iswpunct,setlocale,wcscoll,iscntrl,iswalpha,iswspace,strcoll,wcstod,isdigit,iswblank,iswupper,strerror, wcstombs,isgraph,iswcntrl,iswxdigit,strtod,wcsxfrm,islower,iswctype,isxdigit.Original:
Because
setlocale modifies global state which affects execution of locale-dependent functions, it is undefined behavior to call it from one thread, while another thread is executing any of the following functions: fprintf, isprint, iswdigit, localeconv, tolower, fscanf, ispunct, iswgraph, mblen, toupper, isalnum, isspace, iswlower, mbstowcs, towlower, isalpha, isupper, iswprint, mbtowc, towupper, isblank, iswalnum, iswpunct, setlocale, wcscoll, iscntrl, iswalpha, iswspace, strcoll, wcstod, isdigit, iswblank, iswupper, strerror, wcstombs, isgraph, iswcntrl, iswxdigit, strtod, wcsxfrm, islower, iswctype, isxdigit.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 为例
#include <time.h> #include <locale.h> #include <time.h> #include <locale.h> int main() { time_t now; struct tm *timeinfo; char buf[100]; time(&now); timeinfo = localtime(&now); printf("Locale is :%s\n", setlocale(LC_ALL, NULL)); strftime(buf, 100, "%c", timeinfo); printf("now is :%s\n", buf); setlocale(LC_ALL, ""); printf("Locale is :%s\n", setlocale(LC_ALL, NULL)); strftime(buf, 100, "%c", timeinfo); printf("now is :%s\n", buf); return 0; }
Output:
Locale is :C now is :05/12/13 00:39:28 Locale is :Chinese (Simplified)_People's Republic of China.936 now is :2013/5/12 0:39:28
[编辑] 另请参阅
| setlocale的语言环境类别 Original: locale categories for setlocale The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (宏不变) | |
| C++ documentation for setlocale
| |