C++ Locale Library - constructor



Description

It is a locale constructor.

Declaration

Following is the declaration for std::locale::locale.

C++98

	
   locale() throw();
   locale (const locale& x) throw();
   explicit locale (const char* std_name);	
   locale (const locale& x, const char* std_name, category cats);
   template <class Facet>
   locale (const locale& x, const locale& y, category cats);
   locale (const locale& x, Facet* f);

C++11

   locale() noexcept;	
   locale (const locale& x) noexcept;
explicit locale (const char* std_name);
explicit locale (const string& std_name); 	
   locale (const locale& x, const char* std_name, category cats);
   locale (const locale& x, const string& std_name, category cats);
   template <class Facet>
   locale (const locale& x, const locale& y, category cats);	
   locale (const locale& x, Facet* f);

Parameters

  • x − It copied locale.

  • std_name − It is a standard C-locale name.

  • cats − It contains set of categories that are used from the locale specified as second argument.

  • p &minusl; It is a pointer to a facet object.

  • y − it is a locale object from which the facets specified in cats are used.

Return Value

It returns previous global locale object.

Exceptions

Strong guarantee − if an exception is thrown, there are no effects.

Example

In below example for std::locale::locale.

#include <iostream>
#include <locale>

int main (void) {
   std::locale foo;
   foo.global(std::locale(""));
   std::locale bar;

   std::cout << "bar and foo both are ";
   std::cout << (foo==bar?"the same":"different");
   std::cout << ".\n";

   return 0;
}

The sample output should be like this −

bar and foo both are different.
locale.htm
Advertisements