setlocale
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <locale.h> 中定义
|
||
char* setlocale( int category, const char* locale); |
||
setlocale
功能安装指定的系统区域设置或部分作为新的C语言环境。的修改仍然有效,并影响到执行的所有语言环境敏感的C库函数,直到下一次调用setlocale
。 locale
是一个空指针,setlocale
查询当前的C语言环境,而无需修改原文:
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.目录 |
[编辑] 参数
category | - | 宏之一。可能是空的 |
locale | - | 系统特定的区域设置标识符。 ""为用户首选的语言环境或的最小的语言环境。"C"功能安装指定的系统区域设置或修改的部分作为新的C语言环境。留在效果和影响所有语言环境敏感的C库函数的执行
原文: system-specific locale identifier. Can be "" for the user-preferred locale or "C" for the minimal locale |
[编辑] 返回值
指针到一个狭窄的null结尾的字符串识别应用变更后的C语言环境,如果有的话,则返回null指针,失败.
原文:
pointer to a narrow null-terminated string identifying the C locale after applying the changes, if any, or null pointer on failure.
[编辑] 注释
在程序启动时,相当于setlocale(LC_ALL, "C");任何用户代码运行之前执行.
原文:
During program startup, the equivalent of setlocale(LC_ALL, "C"); is executed before any user code is run.
虽然返回类型是char*,修改所指向的字符是不确定的行为.
原文:
Although the return type is char*, modifying the pointed-to characters is undefined behavior.
,因为
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.原文:
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.[编辑] 示例
#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; }
输出:
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的语言环境类别 (常量宏) | |
C++ documentation for setlocale
|