For faster navigation, this Iframe is preloading the Wikiwand page for Locale.h.

Locale.h

locale.hC程式设计语言标准函数库的一个头文件,声明了C语言本地化函数[1][2] 这些函数用于在处理多种自然语言的软件编程设计时,把程序调整到特定的区域设置. 这些区域设置影响到C语言标准库的输入/输出函数.

所包含的函数

[编辑]

C语言本地化函数与数据类型定义在locale.h (clocale头文件用于C++).[3]

Function Description
setlocale 设置与读取当前C locale
localeconv 返回当前locale的货币与数值的格式细节

批评

[编辑]

C语言标准中定义的区域设置函数的最大问题是,区域设置状态是全局的。这意味着一个程序在一个时刻只能有一个locale设置。实现程序同时具有多个locale是非常困难的。[4]

Visual C++运行时刻库定义了函数_configthreadlocale[5],可以打开或者关闭线程相关区域设置(thread-specific locale)。另外一个运行时刻库函数_setmbcp,在线程中创建限于本线程使用的区域设置数据结构。此后,就可以在该线程使用setlocale标准库函数了。但此种方法仅限于Windows平台。

例子

[编辑]
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>

int main(void)
{
    /* Locale is set to "C" before this. This call sets it
       to the "current locale" by reading environment variables: */
    setlocale(LC_ALL, "");

    const struct lconv * const currentlocale = localeconv();

    printf("In the current locale, the default currency symbol is: %s\n",
        currentlocale->currency_symbol);

    return EXIT_SUCCESS;
}

参考文献

[编辑]
  1. ^ ISO/IEC 9899:1999 specification (PDF). . p. 204, § 7.11 Localization [2012-09-02]. (原始内容存档 (PDF)于2011-01-24). 
  2. ^ Prata, Stephen. C primer plus. Sams Publishing. 2004. Appendix B, Section V: The Standard ANSI C Library with C99 Additions. ISBN 0-672-32696-5. 
  3. ^ locale.h. utas.edu.au. infosys. [14 September 2011]. (原始内容存档于2012-06-04). 
  4. ^ The Standard C Locale and the Standard C++ Locales. Rogue Wave Software, Inc. 1996 [2012-09-02]. (原始内容存档于2020-02-19). 
  5. ^ Microsoft的MSDN上的相关帮助文章. [2012-09-06]. (原始内容存档于2016-05-19). 
{{bottomLinkPreText}} {{bottomLinkText}}
Locale.h
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?