Kommentar
Åtkomst till den här sidan kräver auktorisering. Du kan prova att logga in eller ändra kataloger.
Åtkomst till den här sidan kräver auktorisering. Du kan prova att ändra kataloger.
The class that describes a locale object that encapsulates culture-specific information as a set of facets that collectively define a specific localized environment.
class locale {
public:
class facet;
class id;
typedef int category;
static const category none, collate, ctype, monetary,
numeric, time, messages, all;
locale();
explicit locale(
const char *_Locname
);
explicit locale(
const string& _Locname
);
locale(
const locale& _Loc,
const locale& _Other,
category cat
);
locale(
const locale& _Loc,
const char *_Locname,
category cat
);
locale(
const locale& _Loc,
const string& _Locname,
category _Cat
);
template<class Facet>
locale(
const locale& _Loc,
Facet *_Fac
);
template<class Facet>
locale combine(
const locale& _Loc
) const;
template<class Elem, class Tr, class Alloc>
bool operator()(
const basic_string<Elem, Tr, Alloc>& _Left,
const basic_string<Elem, Tr, Alloc>& _Right
) const;
string name() const;
bool operator== (
const locale& _Right
) const;
bool operator!=(
const locale& _Right
) const;
static locale global(
const locale& _Right
);
static const locale& classic();
};
Remarks
A facet is a pointer to an object of a class derived from class facet that has a public object of the form:
static locale::id id;
You can define an open-ended set of these facets. You can also construct a locale object that designates an arbitrary number of facets.
Predefined groups of these facets represent the locale categories traditionally managed in the Standard C Library by the function setlocale.
Category collate (LC_COLLATE) includes the facets:
collate<char>
collate<wchar_t>
Category ctype (LC_CTYPE) includes the facets:
ctype<char>
ctype<wchar_t>
codecvt<char, char, mbstate_t>
codecvt<wchar_t, char, mbstate_t>
codecvt<char16_t, char, mbstate_t>
codecvt<char32_t, char, mbstate_t>
Category monetary (LC_MONETARY) includes the facets:
moneypunct<char, false>
moneypunct<wchar_t, false>
moneypunct<char, true>
moneypunct<wchar_t, true>
money_get<char, istreambuf_iterator<char> >
money_get<wchar_t, istreambuf_iterator<wchar_t> >
money_put<char, ostreambuf_iterator<char> >
money_put<wchar_t, ostreambuf_iterator<wchar_t> >
Category numeric (LC_NUMERIC) includes the facets:
num_get<char, istreambuf_iterator<char> >
num_get<wchar_t, istreambuf_iterator<wchar_t> >
num_put<char, ostreambuf_iterator<char> >
num_put<wchar_t, ostreambuf_iterator<wchar_t> >
numpunct<char>
numpunct<wchar_t>
Category time (LC_TIME) includes the facets:
time_get<char, istreambuf_iterator<char> >
time_get<wchar_t, istreambuf_iterator<wchar_t> >
time_put<char, ostreambuf_iterator<char> >
time_put<wchar_t, ostreambuf_iterator<wchar_t> >
Category messages (LC_MESSAGES) includes the facets:
messages<char>
messages<wchar_t>
(The last category is required by Posix, but not the C Standard.)
Some of these predefined facets are used by the iostreams classes, to control the conversion of numeric values to and from text sequences.
An object of class locale also stores a locale name as an object of class string. Using an invalid locale name to construct a locale facet or a locale object throws an object of class runtime_error. The stored locale name is "*" if the locale object cannot be certain that a C-style locale corresponds exactly to that represented by the object. Otherwise, you can establish a matching locale within the Standard C Library, for the locale object _Loc, by calling setlocale(LC_ALL, _Loc.name().c_str()).
In this implementation, you can also call the static member function:
static locale empty( );
to construct a locale object that has no facets. It is also a transparent locale; if the template functions has_facet and use_facet cannot find the requested facet in a transparent locale, they consult first the global locale and then, if that is transparent, the classic locale. Thus, you can write:
cout.imbue(locale::empty( ));
Subsequent insertions to cout are mediated by the current state of the global locale. You can even write:
locale loc(locale::empty( ), locale::classic( ),
locale::numeric);
cout.imbue(loc);
Numeric formatting rules for subsequent insertions to cout remain the same as in the C locale, even as the global locale supplies changing rules for inserting dates and monetary amounts.
Constructors
Creates a locale, or a copy of a locale, or a copy of locale where a facet or a category has been replaced by a facet or category from another locale. |
Typedefs
An integer type that provides bitmask values to denote standard facet families. |
Member Functions
Inserts a facet from a specified locale into a target locale. |
|
Returns the stored locale name. |
Static Functions
The static member function returns a locale object that represents the classic C locale. |
|
Resets the default local for the program. |
Operators
Tests two locales for inequality. |
|
Compares two basic_string objects. |
|
Tests two locales for equality. |
Classes
A class that serves as the base class for all locale facets. |
|
The member class provides a unique facet identification used as an index for looking up facets in a locale. |
Requirements
Header: <locale>
Namespace: std
See Also
Reference
Thread Safety in the Standard C++ Library