Set locale - C++ Internationalization

C++ examples for Internationalization:Locale

Introduction

  • LC_ALL refers to all localization categories.
  • LC_COLLATE affects the collating functions, such as strcoll( ).
  • LC_CTYPE alters the way the character functions work.
  • LC_MONETARY determines the monetary format.
  • LC_NUMERIC determines the numeric format.
  • LC_TIME determines the behavior of the strftime( ) function.

The setlocale( ) function returns a pointer to a string associated with the what parameter.

Demo Code

#include <iostream>
#include <ctime>
#include <clocale>
using namespace std;
int main() {/*from   w w w .jav a 2  s  . co m*/
   char str[64];
   // Set the locale to Germany.
   setlocale(LC_ALL, "German_Germany");
   // Get the current system time.
   time_t t = time(NULL);
   // Show standard time and date string.
   strftime(str, 64, "%c", localtime(&t));
   cout << "Standard format: " << str << endl;
   // Show a custom time and date string.
   strftime(str, 64, "%A, %B %Y %I:%M %p", localtime(&t));
   cout << "Custom format: " << str << endl;
   return 0;
}

Result


Related Tutorials