Re: Disabling localisation for an app



On Thu, 2008-10-16 at 22:07 +0200, Søren Hauberg wrote:
> 2008/10/16 klaus triendl <klaus triendl eu>:
> > Søren Hauberg schrieb:
> >> Thanks. I didn't know the 'setlocale' function, which was the one I
> >> needed. I've just added a 'setlocale (LC_ALL, "C");' to my code, as I
> >> don't want any locale changes anywhere in the application.
> >
> > Beware, c++ functionality like iostreams uses its own locale.
> > So you need to call additionally std::locale::global("C") to change the
> > c++ locale to "C" on a global scale.
> 
> Thanks for the heads up -- I'm sure that one probably have confused me
> at some point in the future. For the record, it seems
> std::locale::global expects a std::locale and not a string, so the
> extra needed line is 'std::locale::global (std::locale ("C"));'

one small note on this: one of the reasons why i prefer to use locale
settings for stdio (C) only is that it allows me to leave iostreams free
to take of localization for actual user interaction. i simply ensure
that i use stdio to store configuration data etc etc, and iostreams to
present and collection from the user. i would not have commented on this
until recently, when i was using ebay.de which insisted that i enter 1
euro and 50 cents as "1,50" rather than "1.50". although the error
message was not helpful, i believe the behaviour was correct given
national conventions. if you switch all of iostreams to "C" as well, its
becomes a bit more problematic to parse user input in a way that takes
localization into account, or present it to them in the "typical" way.

but it might not matter :)

--p




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]