📄 locale2.html
字号:
<P><B><CODE><A HREF="#locale::category">category</A>· <A HREF="#locale::classic">classic</A>· <A HREF="#locale::combine">combine</A>· <A HREF="#locale::facet">facet</A>· <A HREF="#locale::global">global</A>· <A HREF="#locale::id">id</A>· <A HREF="#locale::locale">locale</A>· <A HREF="#locale::name">name</A>· <A HREF="#locale::operator!=">operator!=</A>· <A HREF="#locale::operator()">operator()</A>· <A HREF="#locale::operator==">operator==</A></CODE></B></P><HR><PRE>class <B>locale</B> {public: class <B><A HREF="#locale::facet">facet</A></B>; class <B><A HREF="#locale::id">id</A></B>; typedef int <B><A HREF="#locale::category">category</A></B>; static const category <B>none</B>, <B>collate</B>, <B>ctype</B>, <B>monetary</B>, <B>numeric</B>, <B>time</B>, <B>messages</B>, <B>all</B>; <B><A HREF="#locale::locale">locale</A></B>(); explicit <B><A HREF="#locale::locale">locale</A></B>(const char *locname); <B><A HREF="#locale::locale">locale</A></B>(const locale& loc, const locale& other, category cat); <B><A HREF="#locale::locale">locale</A></B>(const locale& loc, const char *locname, category cat); template<class Facet> <B><A HREF="#locale::locale">locale</A></B>(const locale& loc, Facet *fac); template<class Facet> locale <B><A HREF="#locale::combine">combine</A></B>(const locale& loc) const; template<class Elem, class Tr, class Alloc> bool <B><A HREF="#locale::operator()">operator()</A></B>(const basic_string<Elem, Tr, Alloc>& left, const basic_string<Elem, Tr, Alloc>& right) const; string <B><A HREF="#locale::name">name</A></B>() const; bool <B><A HREF="#locale::operator==">operator==</A></B>(const locale& right) const; bool <B><A HREF="#locale::operator!=">operator!=</A></B>(const locale& right) const; static locale <B><A HREF="#locale::global">global</A></B>(const locale& right); static const locale& <B><A HREF="#locale::classic">classic</A></B>(); };</PRE><P>The class describes a<B><A NAME="locale object">locale object</A></B> that encapsulates a<A HREF="locale.html#locale">locale</A>. It representsculture-specific information as a list of<B><A NAME="locale facet">facets</A></B>. A facet is apointer to an object of a classderived from class <CODE><A HREF="#locale::facet">facet</A></CODE>that has a public object of the form:<PRE>static locale::id id;</PRE><P>You can define an open-ended set of these facets. You can alsoconstruct a locale object that designates an arbitrary number offacets.</P><P>Predefined groups of these facets represent the<A HREF="locale.html#locale category">locale categories</A>traditionally managed in the Standard C library by the function<CODE><A HREF="locale.html#setlocale">setlocale</A></CODE>.</P><P>Category <B><CODE><A HREF="#locale::collate">collate</A></CODE></B>(<CODE><A HREF="locale.html#LC_COLLATE">LC_COLLATE</A></CODE>)includes the facets:</P><PRE>collate<char>collate<wchar_t></PRE><P>Category <B><CODE><A HREF="#locale::ctype">ctype</A></CODE></B>(<CODE><A HREF="locale.html#LC_CTYPE">LC_CTYPE</A></CODE>)includes the facets:</P><PRE>ctype<char>ctype<wchar_t>codecvt<char, char, mbstate_t>codecvt<wchar_t, char, mbstate_t></PRE><P>Category <B><CODE><A HREF="#locale::monetary">monetary</A></CODE></B>(<CODE><A HREF="locale.html#LC_MONETARY">LC_MONETARY</A></CODE>)includes the facets:</P><PRE>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> ></PRE><P>Category <B><CODE><A HREF="#locale::numeric">numeric</A></CODE></B>(<CODE><A HREF="locale.html#LC_NUMERIC">LC_NUMERIC</A></CODE>)includes the facets:</P><PRE>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></PRE><P>Category <B><CODE><A HREF="#locale::time">time</A></CODE></B>(<CODE><A HREF="locale.html#LC_TIME">LC_TIME</A></CODE>)includes the facets:</P><PRE>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> ></PRE><P>Category <B><CODE><A HREF="#locale::messages">messages</A></CODE></B>(<CODE>LC_MESSAGES</CODE>) includes the facets:</P><PRE>messages<char>messages<wchar_t></PRE><P>(The last category is required by Posix, but not the C Standard.)</P><P>Some of these predefined facets are used by the<A HREF="lib_cpp.html#iostreams">iostreams</A> classes,to control the conversion of numeric values to and fromtext sequences.</P><P>An object of class <CODE>locale</CODE> also stores a<B><A NAME="locale name">locale name</A></B> as an object of class<CODE><A HREF="string2.html#string">string</A></CODE>. Using aninvalid locale name to construct a<A HREF="#locale facet">locale facet</A> or a locale objectthrows an object of class<CODE><A HREF="stdexcep.html#runtime_error">runtime_error</A></CODE>.The stored locale name is <CODE>"*"</CODE> if the locale objectcannot be certain that a C-style locale corresponds exactlyto that represented by the object. Otherwise, you can establisha matching locale within the Standard C library,for the locale object <CODE>loc</CODE>, by calling<CODE><A HREF="locale.html#setlocale">setlocale</A>(<A HREF="locale.html#LC_ALL">LC_ALL</A>,loc.<A HREF="#locale::name">name</A>.<A HREF="string2.html#basic_string::c_str">c_str</A>())</CODE>.</P><P>In this<A HREF="index.html#implementation">implementation</A>,you can also call the static member function:</P><PRE>static locale <B><A NAME="locale::empty">empty</A></B>();</PRE><P>to construct a locale object that has no facets. It is also a<B><A NAME="transparent locale">transparent locale</A></B> --if the template functions<CODE><A HREF="#has_facet">has_facet</A></CODE> and<CODE><A HREF="#use_facet">use_facet</A></CODE> cannot findthe requested facet in a transparent locale, they consult first the<A HREF="#global locale">global locale</A> and then,if that is transparent, the<A HREF="#classic locale">classic locale</A>. Thus, you can write:</P><PRE>cout.imbue(locale::empty());</PRE><P>Subsequent insertions to<CODE><A HREF="iostream.html#cout">cout</A></CODE> aremediated by the current state of the global locale.You can even write:</P><PRE>locale loc(locale::empty(), locale::classic(), locale::numeric);cout.imbue(loc);</PRE><P>Numeric formatting rules for subsequent insertions to<CODE>cout</CODE> remain the same as in the<A HREF="locale.html#C locale">C locale</A>,even as the global locale supplies changing rules for insertingdates and monetary amounts.</P><H3><CODE><A NAME="locale::category">locale::category</A></CODE></H3><PRE>typedef int <B>category</B>;static const category <B>none</B>, <B>collate</B>, <B>ctype</B>, <B>monetary</B>, <B>numeric</B>, <B>time</B>, <B>messages</B>, <B>all</B>;</PRE><P>The type is a synonym for <I>int</I> so that it can representany of the C <A HREF="locale.html#locale category">locale categories</A>.It can represent a group of distinct elements of a<A HREF="lib_cpp.html#bitmask type">bitmask type</A>(which is anonymous) local to class <CODE>locale</CODE>.The elements are:</P><UL><LI><B><CODE><A NAME="locale::collate">collate</A></CODE></B>,corresponding to the C category<CODE><A HREF="locale.html#LC_COLLATE">LC_COLLATE</A></CODE></LI><LI><B><CODE><A NAME="locale::ctype">ctype</A></CODE></B>,corresponding to the C category<CODE><A HREF="locale.html#LC_CTYPE">LC_CTYPE</A></CODE></LI><LI><B><CODE><A NAME="locale::monetary">monetary</A></CODE></B>,corresponding to the C category<CODE><A HREF="locale.html#LC_MONETARY">LC_MONETARY</A></CODE></LI><LI><B><CODE><A NAME="locale::numeric">numeric</A></CODE></B>,corresponding to the C category<CODE><A HREF="locale.html#LC_NUMERIC">LC_NUMERIC</A></CODE></LI><LI><B><CODE><A NAME="locale::time">time</A></CODE></B>,corresponding to the C category<CODE><A HREF="locale.html#LC_TIME">LC_TIME</A></CODE></LI><LI><B><CODE><A NAME="locale::messages">messages</A></CODE></B>,corresponding to the Posix category<CODE>LC_MESSAGES</CODE></LI></UL><P>In addition, two useful values are:</P><UL><LI><B><CODE><A NAME="locale::none">none</A></CODE></B>, corresponding to none ofthe C categories</LI><LI><B><CODE><A NAME="locale::all">all</A></CODE></B>,corresponding to the C union of all categories<CODE><A HREF="locale.html#LC_ALL">LC_ALL</A></CODE></LI></UL><P>You can represent an arbitrary group of categories by ORingthese constants, as in <CODE>monetary | time</CODE>.</P><H3><CODE><A NAME="locale::classic">locale::classic</A></CODE></H3><PRE>static const locale& <B>classic</B>();</PRE><P>The static member function returns a locale object that represents the<B><A NAME="classic locale">classic locale</A></B>,which behaves the same as the<A HREF="locale.html#C locale">C locale</A> within theStandard C library.</P><H3><CODE><A NAME="locale::combine">locale::combine</A></CODE></H3><PRE>template<class Facet> locale <B>combine</B>(const locale& loc) const;</PRE><P>The member function returns a locale object thatreplaces in (or adds to) <CODE>*this</CODE> the facet <CODE>Facet</CODE>listed in <CODE>loc</CODE>.</P><H3><CODE><A NAME="locale::facet">locale::facet</A></CODE></H3><PRE>class <B>facet</B> {protected: explicit <B>facet</B>(size_t refs = 0); virtual <B>~facet</B>();private: <B>facet</B>(const facet&) // not defined <B>void operator=</B>(const facet&) // not defined };</PRE><P>The member class serves as the base class for all<A HREF="#locale facet">locale facets</A>. Note that youcan neither copy nor assign an object of class <CODE>facet</CODE>.You can construct and destroy objects derived from class<CODE>locale::facet</CODE>, but not objects of the base class proper.Typically, you construct an object <CODE>myfac</CODE> derivedfrom <CODE>facet</CODE> when you construct a locale, as in:</P><PRE>locale loc(locale::classic(), new myfac);</PRE><P>In such cases, the constructor for the base class <CODE>facet</CODE>should have a zero <CODE>refs</CODE> argument. When the objectis no longer needed, it is deleted. Thus, you supply a nonzero<CODE>refs</CODE> argument only in those rare cases where youtake responsibility for the lifetime of the object.</P><H3><CODE><A NAME="locale::global">locale::global</A></CODE></H3><PRE>static locale <B>global</B>(const locale& loc);</PRE><P>The static member function stores a copy of <CODE>loc</CODE> as the<B><A NAME="global locale">global locale</A></B>. It also calls<CODE><A HREF="locale.html#setlocale">setlocale</A>(<A HREF="locale.html#LC_ALL">LC_ALL</A>,loc.<A HREF="#locale::name">name</A>.<A HREF="string2.html#basic_string::c_str">c_str</A>())</CODE>,to establishing a matching locale within the Standard C library.The function then returns the previous global locale. At<A HREF="lib_over.html#program startup">program startup</A>,the global locale is the same as the<A HREF="#classic locale">classic locale</A>.</P><H3><CODE><A NAME="locale::id">locale::id</A></CODE></H3><PRE>class <B>id</B> {protected: <B>id</B>();private: <B>id</B>(const id&) // not defined <B>void operator=</B>(const id&) // not defined };</PRE><P>The member class describes the staticmember object required by each unique<A HREF="#locale facet">locale facet</A>. Note that youcan neither copy nor assign an object of class <CODE>id</CODE>.</P><H3><CODE><A NAME="locale::locale">locale::locale</A></CODE></H3><PRE><B>locale</B>();explicit <B>locale</B>(const char *locname);<B>locale</B>(const locale& loc, const locale& other, category cat);<B>locale</B>(const locale& loc, const char *locname, category cat);template<class Facet> <B>locale</B>(const locale& loc, Facet *fac);</PRE><P>The first constructor initializes the object to match the<A HREF="#global locale">global locale</A>. The second constructorinitializes all the<A HREF="locale.html#locale category">locale categories</A> to have behaviorconsistent with the <A HREF="#locale name">locale name</A><CODE>locname</CODE>. The remaining constructors copy <CODE>loc</CODE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -