By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,665 Members | 1,761 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,665 IT Pros & Developers. It's quick & easy.

locale question

P: n/a
Greetings.

I am confused about C++ standard library locale stuff. It seems as if the
implementations of locales are not part of the library, but only some
guideline classes are there.

What is the standard conformant way of formatting and parsing locale
specific date, time, strings with various character encoding, etc.

Thanks
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
> I am confused about C++ standard library locale stuff. It seems as if the
implementations of locales are not part of the library, but only some
guideline classes are there.

What is the standard conformant way of formatting and parsing locale
specific date, time, strings with various character encoding, etc.

Thanks


Typically you'll use a locale through a stream but you can also use them
directly. When working with a stream, you simply invoke the stream's "imbue"
member, passing your "locale" object which is encapsulated in the stream.
You can read up on the various locale constructors but the "C" locale (AKA
locale::classic) is used by default (actually, the "locale::global" object
is used but it originates from "locale::classic" unless you change it). You
can pass other implementation-defined strings to a locale's constructor
however, typically based on RFC 1766 which in turn is based on ISO 639 and
3166 - try passing "en-US" (English US ) or "fr-CA" (French Canadian) for
instance or consult your local implementation for details). Subsequently,
whenever you invoke the << or >> operators on your stream, the stream will
handle the date, time, etc. according to the facets stored in the
encapsulated locale (a locale is really just a collection of facet objects
such as "num_put", "time_put", "numpunct" etc.). You can also store your own
customized facets in an existing locale however or provide overrides for the
various (facet) member functions as required. In any case, everything boils
down to invoking the "use_facet()" function template, passing a given
facet's class name as the template arg, the locale you want as the
function's arg, and then invoking a particular member of that facet's class
(that is, a reference to the requested facet object is returned by this
function and you just invoke the member you're interested in). "use_facet()"
is rather ugly to call as you'll soon see (the entire locale/facet design is
ugly IMO) but you should consult this function for details. Also see
"has_facet()" to ensure a facet is even supported by a given locale.
Everything should become clear once you understand "use_facet()" which
forces you to address the issues you're asking about (also note that the <<
and >> stream operators defer to this function in case that's not clear by
now).
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.