locale question

Discussion in 'C++' started by Cagdas Ozgenc, Nov 4, 2003.

  1. 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
     
    Cagdas Ozgenc, Nov 4, 2003
    #1
    1. Advertising

  2. Cagdas Ozgenc

    Mark Kerns Guest

    > 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).
     
    Mark Kerns, Nov 4, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Maurice Hulsman
    Replies:
    1
    Views:
    1,873
    Guus Bosman
    Jul 25, 2004
  2. Replies:
    4
    Views:
    1,016
  3. Gabriel Genellina
    Replies:
    0
    Views:
    715
    Gabriel Genellina
    Feb 18, 2009
  4. zade
    Replies:
    1
    Views:
    623
    James Kanze
    Mar 5, 2010
  5. Sibylle Koczian
    Replies:
    2
    Views:
    1,132
    Sibylle Koczian
    Nov 20, 2010
Loading...

Share This Page