代码页Code Pages

代码页是一个字符集,可以包括数字、标点符号和其他标志符号。code pageA code page is a character set, which can include numbers, punctuation marks, and other glyphs. 不同的语言和区域设置可能使用不同的代码页。Different languages and locales may use different code pages. 例如,ANSI 代码页 1252 适用于英语和大多数欧洲语言;而 OEM 代码页 932 则适用于日本汉字。For example, ANSI code page 1252 is used for English and most European languages; OEM code page 932 is used for Japanese Kanji.

代码页可以用字符与单字节值或多字节值的映射表来表示。A code page can be represented in a table as a mapping of characters to single-byte values or multibyte values. 对于 0x00 - 0x7F 范围的字符,大多数代码页共享 ASCII 字符集。Many code pages share the ASCII character set for characters in the range 0x00 - 0x7F.

Microsoft 运行库使用以下类型的代码页:The Microsoft run-time library uses the following types of code pages:

  • 系统默认的 ANSI 代码页。System-default ANSI code page. 默认情况下,启动时运行系统将多字节代码页自动设置为系统默认的 ANSI 代码页(可从操作系统中获得)。By default, at startup the run-time system automatically sets the multibyte code page to the system-default ANSI code page, which is obtained from the operating system. 调用:The call:

    setlocale ( LC_ALL, "" );  
    

    也可将区域设置设置为系统默认 ANSI 代码页。also sets the locale to the system-default ANSI code page.

  • 区域设置代码页。Locale code page. 大量运行时例程的行为取决于当前的区域设置(包括区域设置代码页)。The behavior of a number of run-time routines is dependent on the current locale setting, which includes the locale code page. (有关详细信息,请参阅与区域设置相关的例程。)默认情况下,Microsoft 运行库中的所有与区域设置相关的例程使用对应于“C”区域设置的代码页。(For more information, see Locale-Dependent Routines.) By default, all locale-dependent routines in the Microsoft run-time library use the code page that corresponds to the "C" locale. 运行时可使用对 setlocale 的调用来更改或查询所使用的区域设置代码页。At run-time you can change or query the locale code page in use with a call to setlocale.

  • 多字节代码页。Multibyte code page. 运行库中的大部分多字节字符例程的行为取决于当前的多字节代码页设置。The behavior of most of the multibyte-character routines in the run-time library depends on the current multibyte code page setting. 默认情况下,这些例程使用系统默认的 ANSI 代码页。By default, these routines use the system-default ANSI code page. 运行时可分别使用 _getmbcp_setmbcp 查询和更改多字节代码页。At run-time you can query and change the multibyte code page with _getmbcp and _setmbcp, respectively.

  • ANSI 定义“C”区域设置以与传统上用来执行 C 程序的区域设置相对应。The "C" locale is defined by ANSI to correspond to the locale in which C programs have traditionally executed. “C”区域设置的代码页(“C”代码页)对应于 ASCII 字符集。The code page for the "C" locale ("C" code page) corresponds to the ASCII character set. 例如,在“C”区域设置中,只有对于 0x61 - 0x7A 范围的值,islower 才会返回 true。For example, in the "C" locale, islower returns true for the values 0x61 - 0x7A only. 在另一个区域设置中,islower 可能会为这些值或其他值(由该区域设置定义)返回 true。In another locale, islower may return true for these as well as other values, as defined by that locale.

请参阅See Also

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