Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: BigAngryDog on March 05, 2006, 06:47:40 am

Title: MinGW support for std::locale?
Post by: BigAngryDog on March 05, 2006, 06:47:40 am
Am I correct in thinking the MinGW compiler (with Code::Blocks) does not support any locale other than the C locale?

I.e., the following raises an error:

Code
std::locale("en_US");

Sorry if this is numptie, question but I am new to MinGW & C::B.

Thanks
Title: Re: MinGW support for std::locale?
Post by: thomas on March 05, 2006, 09:27:38 am
You should catch exceptions as described in Locales (http://public.research.att.com/~bs/3rd_loc.pdf) to prevent your app from crashing.

Code
#include <iostream>
#include <stdexcept>
#include <locale>

int main()
{
    std::locale loc;
    try
    {
        loc = std::locale("en_US");
    }
    catch (std::runtime_error)
    {
        std::cerr << "locale not found\n";
        loc = std::locale("");       
    }
    return 0;
}
Should always work just fine. Empty string creates the default locale defined by the user's OS preferences (whatever that is). "en_US" like you used it should work too, if all is installed correctly (as it happens, it fails on my system,too - but that is not surprising, I don't have en_US).

In any case, always catch exceptions because locale will throw if anything goes wrong (as most things in std do).
Title: Re: MinGW support for std::locale?
Post by: BigAngryDog on March 05, 2006, 02:31:31 pm
Thanks for the reply thomas.

You say:

>"en_US" like you used it should work too, if all is installed correctly

That's interesting. How do I install a locale in my C::B/MinGW development environment?

Cheers
Title: Re: MinGW support for std::locale?
Post by: thomas on March 05, 2006, 03:41:44 pm
As far as I know, this is not a matter of MinGW installation, but of OS installation (since the standard library only supports the "C" locale and the "" locale itself). The other locales are provided by the OS. Don't take my word for it, though ;)
Title: Re: MinGW support for std::locale?
Post by: BigAngryDog on March 05, 2006, 07:00:54 pm
Out of interest, I note that Borland BCB not only allows me to set a range of std::locale("...") values, but they also do stuff, i.e. they change locale dependent behaviour. However, MinGW throws an exception if you try to set a locale to anything other than C classic.

There seems so much in the standard library with is "implementation specific"! Just my thought for the day. :)

Thanks for replying. Cheers.