C++ Standard Library C++ STL Library

C++ <clocale> - LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME



The C++ <clocale> contains LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME macro constants. Each of these macro constants expand to integer constant expressions with distinct values that are suitable for use with setlocale() function as the first argument.

MacrosDescription
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.

Definition in the <clocale> header file is:

#define LC_ALL      /* implementation defined */
#define LC_COLLATE  /* implementation defined */
#define LC_CTYPE    /* implementation defined */
#define LC_MONETARY /* implementation defined */
#define LC_NUMERIC  /* implementation defined */
#define LC_TIME     /* implementation defined */

Example:

The example below shows the usage of these macros.

#include <cstdio>
#include <ctime>
#include <clocale>
 
int main (){
  time_t t = time(NULL);
  char buffer [80];

  printf("Local is: %s\n", setlocale(LC_ALL,"C"));

  //monetary formatting will be US
  setlocale(LC_MONETARY, "en_US.UTF-8");  
  struct lconv *lc = localeconv();

  printf("Local Currency Symbol: %s\n", 
          lc->currency_symbol);

  //time formatting will be environment's 
  //default locale
  setlocale(LC_TIME, ""); 
  strftime (buffer,80,"%c",localtime(&t));
  printf("Date is: %s\n", buffer);

  return 0;
}

The output of the above code will be:

Local is: C
Local Currency Symbol: $
Date is: Mon May 10 07:41:59 2021

❮ C++ <clocale> Library