Namespaces
Variants
Views
Actions

LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME

From cppreference.com
< c‎ | locale
Revision as of 20:11, 2 November 2012 by P12bot (Talk | contribs)

Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <locale.h>
</td>

<td></td> <td></td> <tr class="t-dcl ">

<td class="t-dcl-nopad">
#define LC_ALL      /*implementation defined*/
</td>

<td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td class="t-dcl-nopad">
#define LC_COLLATE  /*implementation defined*/
</td>

<td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td class="t-dcl-nopad">
#define LC_CTYPE    /*implementation defined*/
</td>

<td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td class="t-dcl-nopad">
#define LC_MONETARY /*implementation defined*/
</td>

<td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td class="t-dcl-nopad">
#define LC_NUMERIC  /*implementation defined*/
</td>

<td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td class="t-dcl-nopad">
#define LC_TIME     /*implementation defined*/
</td>

<td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end

Each of the above macro constants expand to integer constant expressions with distinct values that are suitable for use as the first argument of setlocale.

Constant Explanation
LC_ALL selects the entire C locale
LC_COLLATE selects the collation category of the C locale
LC_CTYPE selects the character classification category of the C locale
LC_MONETARY selects the monetary formatting category of the C locale
LC_NUMERIC selects the numeric formatting category of the C locale
LC_TIME selects the time formatting category of the C locale

Additional macro constants, with names that begin with LC_ followed by at least one uppercase letter, may be defined in locale.h. For example, the POSIX specification requires LC_MESSAGES and the GNU C library additionally defines LC_PAPER, LC_NAME, LC_ADDRESS, LC_TELEPHONE, LC_MEASUREMENT, and LC_IDENTIFICATION.

Example

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

Output:

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

See also

Template:c/locale/dcl list setlocale
C++ documentation for locale categories