Namespaces
Variants
Views
Actions

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

From cppreference.com
< cpp‎ | locale‎ | locale
m (Text replace - "{{cpp|" to "{{c|")
(- {{dcl header|locale}})
 
(9 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{cpp/locale/locale/title | global}}
+
{{cpp/locale/locale/title|global}}
{{cpp/locale/locale/sidebar}}
+
{{cpp/locale/locale/navbar}}
  
{{ddcl | header=locale |
+
{{ddcl|
 
static locale global( const locale& loc );
 
static locale global( const locale& loc );
 
}}
 
}}
  
Replaces the global C++ locale with {{tt|loc}}, which means all future calls to the {{c|std::locale}} default constructor will now return a copy of {{tt|loc}}. If {{tt|loc}} has a name, also replaces the C locale as if by {{c|1=std::setlocale(LC_ALL, loc.name().c_str());}}. This function is the only way to modify the global C++ locale, which is otherwise equivalent to {{c|std::locale::classic()}} at program startup.
+
Replaces the global C++ locale with {{c|loc}}, which means all future calls to the {{lc|std::locale}} default constructor will now return a copy of {{c|loc}}. If {{c|loc}} has a name, also replaces the C locale as if by {{c|1=std::setlocale(LC_ALL, loc.name().c_str());}}. This function is the only way to modify the global C++ locale, which is otherwise equivalent to {{c|std::locale::classic()}} at program startup.
  
 
===Parameters===
 
===Parameters===
{{param list begin}}
+
{{par begin}}
{{param list item | loc | the new global C++ locale}}
+
{{par|loc|the new global C++ locale}}
{{param list end}}
+
{{par end}}
  
 
===Return value===
 
===Return value===
Line 17: Line 17:
  
 
===Example===
 
===Example===
{{example cpp
+
{{example
|
+
|code=
| code=
+
| output=
+
 
}}
 
}}
 +
 +
===Defect reports===
 +
{{dr list begin}}
 +
{{dr list item|wg=lwg|dr=8|std=C++98|before=it was unspecified whether other library functions (such<br>as {{lc|std::setlocale}}) can modify the global C++ locale|after=specified (no other<br>library functions allowed)}}
 +
{{dr list end}}
  
 
===See also===
 
===See also===
{{dcl list begin}}
+
{{dsc begin}}
{{dcl list template | cpp/locale/locale/dcl list locale}}
+
{{dsc inc|cpp/locale/locale/dsc locale}}
{{dcl list template | cpp/locale/locale/dcl list classic}}
+
{{dsc inc|cpp/locale/locale/dsc classic}}
{{dcl list template | cpp/locale/dcl list setlocale}}
+
{{dsc inc|cpp/locale/dsc setlocale}}
{{dcl list end}}
+
{{dsc end}}
 +
 
 +
{{langlinks|de|es|fr|it|ja|pt|ru|zh}}

Latest revision as of 22:55, 18 October 2024

 
 
 
 
static locale global( const locale& loc );

Replaces the global C++ locale with loc, which means all future calls to the std::locale default constructor will now return a copy of loc. If loc has a name, also replaces the C locale as if by std::setlocale(LC_ALL, loc.name().c_str());. This function is the only way to modify the global C++ locale, which is otherwise equivalent to std::locale::classic() at program startup.

Contents

[edit] Parameters

loc - the new global C++ locale

[edit] Return value

The previous value of the global C++ locale.

[edit] Example

[edit] Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DR Applied to Behavior as published Correct behavior
LWG 8 C++98 it was unspecified whether other library functions (such
as std::setlocale) can modify the global C++ locale
specified (no other
library functions allowed)

[edit] See also

constructs a new locale
(public member function) [edit]
[static]
obtains a reference to the "C" locale
(public static member function) [edit]
gets and sets the current C locale
(function) [edit]