News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

MinGW support for std::locale?

Started by BigAngryDog, March 05, 2006, 06:47:40 AM

Previous topic - Next topic

BigAngryDog

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:


std::locale("en_US");


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

Thanks
[url="//bigangrydog.com"]BigAngryDog.com[/url]

thomas

You should catch exceptions as described in Locales to prevent your app from crashing.

#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).
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

BigAngryDog

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
[url="//bigangrydog.com"]BigAngryDog.com[/url]

thomas

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 ;)
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

BigAngryDog

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.
[url="//bigangrydog.com"]BigAngryDog.com[/url]