Facebook Page Twitter Page LinkedIn Page
× C++ Standard Library C++ STL Library

The C++ <clocale> setlocale() sets the locale information to be used by the current program, either changing the entire locale or portions of it. The function can also be used to retrieve the current locale's name by passing NULL pointer as locale argument.

The modifications remain in effect and influences the execution of all locale-sensitive C library functions until the next call to setlocale() function.


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


category Specify locale category identifier. It is one of the macro constant values defined for locale categories.
locale Specify system-specific locale identifier. These are system specific, but at least the two following locales must exist:
  • "" - Environment's default locale
  • "C" - for the Minimal C locale
If NULL pointer is passed, the function queries the current C locale without modifying it.

Return Value

On success, returns a pointer to a narrow null-terminated string identifying the C locale after applying the changes, if any, or null pointer on failure.


The below example shows the usage of setlocale() function.

#include <iostream>
#include <ctime>
#include <clocale>

using namespace std;
int main (){
  time_t t = time(NULL);
  char buffer [80];

  cout<<"Local is: "<<setlocale(LC_ALL,"")<<"\n";

  struct lconv *lc = localeconv();

  cout<<"Local Currency Symbol: "

  strftime (buffer,80,"%c",localtime(&t));
  cout<<"Date is: "<<buffer<<"\n";

  return 0;

The output of the above code will be:

Local is: en_US.UTF-8
Local Currency Symbol: $
Date is: Wed 07 Apr 2021 08:53:11 AM UTC

❮ C++ <clocale> Library