User forums > Using Code::Blocks
MinGW support for std::locale?
(1/1)
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:
--- Code: ---std::locale("en_US");
--- End code ---
Sorry if this is numptie, question but I am new to MinGW & C::B.
Thanks
thomas:
You should catch exceptions as described in Locales 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;
}
--- End code ---
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).
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
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 ;)
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.
Navigation
[0] Message Index
Go to full version