Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/locale/locale/locale"

From cppreference.com
< cpp‎ | locale‎ | locale
m (Text replace - "{{example cpp" to "{{example")
m (Text replace - "/sidebar" to "/navbar")
Line 1: Line 1:
 
{{cpp/locale/locale/title | locale}}
 
{{cpp/locale/locale/title | locale}}
{{cpp/locale/locale/sidebar}}
+
{{cpp/locale/locale/navbar}}
  
 
{{ddcl list begin}}
 
{{ddcl list begin}}

Revision as of 13:23, 15 June 2012

 
 
 
 

Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <locale>
</td>

<td></td> <td></td> </tr> <tr class="t-dcl ">

<td >
locale();
</td>

<td > (1) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
locale( const locale& other );
</td>

<td > (2) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
explicit locale( const char* std_name );
</td>

<td > (3) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
explicit locale( const std::string& std_name );
</td>

<td > (4) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
locale( const locale& other, const char* std_name, category cat );
</td>

<td > (5) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
locale( const locale& other, const std::string& std_name, category cat );
</td>

<td > (6) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
template< class Facet >
locale( const locale& other, Facet* f );
</td>

<td > (7) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
locale( const locale& other, const locale& one, category cat );
</td>

<td > (8) </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end

1) Default constructor. Constructs a copy of the global C++ locale (that is, the locale most recently used as the argument to std::locale::global or a copy of std::locale::classic if no call to std::locale::global has been made.

2) Copy constructor. Constructs a copy of other.

3-4) Constructs a copy of the system locale with specified std_name (such as "C", or "POSIX", or "en_US.UTF-8", or "English_US.1251"), if such locale is supported by the operating system. The locale constructed in this manner has a name.

5-6) Constructs a copy of other except for all the facets identified by the cat argument, which are copied from the system locale identified by its std_name. The locale constructed in this manner has the same name as other.

7) Constructs a copy of other except for the facet of type Facet (typically deduced from the type of the argument) which is installed from the argument facet. If facet is NULL, the constructed locale is a full copy of other. The locale constructed in this manner has no name.

8) Constructs a copy of other except for all the facets identified by the cat argument, which are copied from one. If both other and one have names, then the resulting locale also has a name.

Contents

Parameters

other - another locale to copy
std_name - name of the system locale to use
f - pointer to a facet to merge with other
cat - the locale category used to identify the facets to merge with other
one - another locale to take facets from

Exceptions

1-2)
noexcept specification:  
noexcept
  

3) std::runtime_error if the operating system has no locale named std_name or if std_name is NULL.

4) std::runtime_error if the operating system has no locale named std_name.

5) std::runtime_error if the operating system has no locale named std_name or if std_name is NULL.

6) std::runtime_error if the operating system has no locale named std_name.

7-8) (none)

Example

#include <iostream>
#include <locale>
#include <codecvt>
 
int main()
{
    std::locale l1;  // l1 is a copy of the classic "C" locale
    std::locale l2("en_US.UTF-8"); // l2 is a unicode locale
    std::locale l3(l1, l2, std::locale::ctype); // l3 is "C" except for ctype, which is unicode
    std::locale l4(l1, new std::codecvt_utf8<wchar_t>); // l4 is "C" except for codecvt
    std::cout << "Locale names:\nl1: " << l1.name() << "\nl2: " << l2.name()
               << "\nl3: " << l3.name() << "\nl4: " << l4.name() << '\n';
}

Output:

Locale names:
l1: C
l2: en_US.UTF-8
l3: LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=C;LC_PAPER=C;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C;LC_IDENTIFICATION=C
l4: *

See also

Template:cpp/locale/locale/dcl list ~locale