What Std::Locale Names Are Available on Common Windows Compilers

What std::locale names are available on common windows compilers?

I believe the information you need is here :

locale  "lang[_country_region[.code_page]]"
| ".code_page"
| ""
| NULL

This page provides links to :

  • Language Strings
  • Country/Region String
  • Code Pages

Although my answers covers setlocale instead of std::locale, this MSDN page seems to imply that the format is indeed the same :

An object of class locale also stores
a locale name as an object of class
string. Using an invalid locale name
to construct a locale facet or a
locale object throws an object of
class runtime_error. The stored
locale name is "*" if the locale
object cannot be certain that a
C-style locale corresponds exactly to
that represented by the object.
Otherwise, you can establish a matching locale within the Standard C
Library, for the locale object loc, by
calling setlocale(LC_ALL,
loc.name.c_str)
.

Also see this page and this thread which tend to show that std::locale internally uses setlocale.

Print all std::locale names (Windows)

I wrote a program to print all supported locale names.

#include <Windows.h>

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <ostream>
#include <iterator>

using namespace std;

vector<wstring> locals;

BOOL CALLBACK MyFuncLocaleEx(LPWSTR pStr, DWORD dwFlags, LPARAM lparam)
{
locals.push_back(pStr);
return TRUE;
}

int _tmain(int argc, _TCHAR* argv[])
{
EnumSystemLocalesEx(MyFuncLocaleEx, LOCALE_ALL, NULL, NULL);

for (vector<wstring>::const_iterator str = locals.begin(); str != locals.end(); ++str)
wcout << *str << endl;

wcout << "Total " << locals.size() << " locals found." << endl;

return 0;
}

Works great.

...
de
de-AT
de-CH
de-DE
de-DE_phoneb
de-LI
de-LU
...
Total 429 locals found.

std::get_time and other locale functionality not working correctly on Windows

The problem exposed here is not
- Wrong locale names
- Wrong std::tm values

But lies exactly in the fact that the %c format specifier does not do what's expected here on Windows. This is easy to fix, by specifying the format in full. In this case, what I used was:

"%a %b %d %H" ":" "%M" ":" "%S %Y"

It still has problems with the %Y part (tm_year is still zero)...



Related Topics



Leave a reply



Submit