This is the mail archive of the
mailing list for the Cygwin project.
Re: how to set locale with C++
On 9 February 2012 15:24, marco atzeri wrote:
> On 2/9/2012 1:37 PM, Corinna Vinschen wrote:
>> On Feb Â9 12:13, marco atzeri wrote:
>>> Attached a small example taken from Bruce Eckel Thinking in C++
>>> On cygwin both this call
>>> Â cout.imbue(locale("en_US.UTF-8"));
>>> Â cout.imbue(locale("fr_FR.UTF-8"));
>>> raise exception
>>> "terminate called after throwing an instance of 'std::runtime_error'
>>> Â what(): Âlocale::facet::_S_create_c_locale name not valid
>>> Aborted (core dumped)"
>>> I could understand eventually the second one, but "English (US)" is
>>> the current windows locale so I expected that at least "en_US.UTF-8"
>>> is accepted.
>>> What I am missing ?
>> This doesn't look like a Cygwin issue. ÂThe above error
>> "locale::facet::_S_create_c_locale name not valid" points to some
>> problem in the library implementing the locale call. ÂThe underlying
>> plain C call setlocale should work fine.
> g++ 4.5.3 seems to have a problem on cygwin.
> setlocale on pure C is working
> (modified from
> $ ./setlocale.exe
> Locale is: C
> Date is: Thu Feb Â9 14:52:45 2012
> Currency symbol is:
> Locale is: fr_FR.UTF-8
> Date is: jeu. Â9 fÃvr. 2012 14:52:45
> Currency symbol is: â
> it could be related to libstdc++ built with a different
> --enable-clocale option ?
The problem is that Cygwin/newlib does not have good enough locale
support. C99 locale support is not good enough for std::locale
implementation. Mainly because the functions that change the locale
affect the whole process. It is necessary to have at least per thread
locale for std::locale to be implementable; it is better to have some
sort of locale structure to pass around. AFAIK this can be
implemented using functions provided by xlocale.h (MacOS X, ).
> Or that functionality is not available on cygwin ?
Problem reports: http://cygwin.com/problems.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple