setlocale() - Time Date Function

How to set / retrieve locale using time date function in C++?


setlocale() date function is used to set / retrieve the locale settings for the program execution. If it is null, it returns a pointer to the current localization string. Following table lists the macros of the specified type.
Macro Descrption
LC_ALL Refers all localization categories.
LC_COLLATE Affects the operation of strcoll() function.
LC_CTYPE Alters the way the character functions work.
LC_MONETARY Determines the monetary format.
LC_NUMERIC Changes the decimal point character for formatted I/O functions.
LC_TIME Determine the functioning of strftime() function.


char *setlocale(int type, const char *locale);

Example :

#include <stdio.h>
#include <locale.h>
int main ()
struct lconv * st;
printf ("Locale is: %s\n", setlocale(LC_ALL,NULL) );
printf ("Currency symbol is: %s\n-\n",st->currency_symbol,
setlocale (LC_ALL,"French") );
return 0;

Result :

Locale is: C
Currency symbol is: ç

In the above example "setlocale()" is used to set / retrieve the locale setting of france, so that the french currency symbol is displayed.

C++ Tutorial

Ask Questions

Ask Question