tags:

views:

56

answers:

1

I attempting to instantiate a std::locale object with the US or GB-English locale string:

std::locale loc("en_US");

or

std::locale loc("en_GB"); 

Both of which throw a bad locale name runtime exception.

Creating a locale using "" or "C" works fine, however I'm having trouble setting an individual country locale.


The reason I'd like to do this is for unit testing purposes to make sure a collection of string sorting methods work correctly.


Note: I should also point out that I'm coding in Windows using Visual Studio 2008 (and I'd like to keep my code cross-platform if possible)

+2  A: 

The strings which std::locale supports are implementation specific. It could be that the implementation you are using doesn't supports the one you are trying.

As you are programming in Windows, you can be interested to Language Strings, which lists the language identifiers used by setlocal, and Country/Region Strings for the country identifiers.

You can find more information on std::locale::global(std::locale("zh-CN")) Gets "Bad locale name"??.

kiamlaluno