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
classruntime_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
callingsetlocale(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
How to Check That an Element Is in a Std::Set
Differencebetween Exit() and Abort()
Is Left-Shifting (<<) a Negative Integer Undefined Behavior in C++11
Copy Elision: Move Constructor Not Called When Using Ternary Expression in Return Statement
Compare Double to Zero Using Epsilon
Visual C++ 2008 Express Download Link Dead
Calling a Virtual Function from the Constructor
Rewinding Std::Cout to Go Back to the Beginning of a Line
Assertion Failed (Size.Width>0 && Size.Height>0)
C++: How to Implement Polymorphic Object Creator to Populate a Table
What Are Your Favorite C++ Coding Style Idioms
How to Remove All Substrings from a String
Valgrind Memory Leak Errors When Using Pthread_Create