setlocale() doesn't work!
-
Hey everybody I have the following code:
wstring curlocale1(::_wsetlocale(LC_ALL, NULL));
printf("+++ current locale: %s", curlocale1.c_str());::_wsetlocale(LC_ALL, L"en_us");
wstring curlocale2(::_wsetlocale(LC_ALL, NULL));
printf("+++ current locale: %s", curlocale2.c_str());and the output is: +++ current locale: C +++ current locale: C I can't understand why my locale does not change, what am I doing wrong? Thanks a lot!
-
Hey everybody I have the following code:
wstring curlocale1(::_wsetlocale(LC_ALL, NULL));
printf("+++ current locale: %s", curlocale1.c_str());::_wsetlocale(LC_ALL, L"en_us");
wstring curlocale2(::_wsetlocale(LC_ALL, NULL));
printf("+++ current locale: %s", curlocale2.c_str());and the output is: +++ current locale: C +++ current locale: C I can't understand why my locale does not change, what am I doing wrong? Thanks a lot!
Used correctly it works fine:
wstring curlocale1(::\_wsetlocale(LC\_ALL, NULL)); printf("+++ current locale: %S\\n", curlocale1.c\_str()); ::\_wsetlocale(LC\_ALL, L"English"); wstring curlocale2(::\_wsetlocale(LC\_ALL, NULL)); printf("+++ current locale: %S\\n", curlocale2.c\_str());
It's time for a new signature.
-
Used correctly it works fine:
wstring curlocale1(::\_wsetlocale(LC\_ALL, NULL)); printf("+++ current locale: %S\\n", curlocale1.c\_str()); ::\_wsetlocale(LC\_ALL, L"English"); wstring curlocale2(::\_wsetlocale(LC\_ALL, NULL)); printf("+++ current locale: %S\\n", curlocale2.c\_str());
It's time for a new signature.
Hey, thanks :-) But "English" doesn't return "English (United States)", but generic English. Anyway, I found this GREAT article in codeproject that sort some things out, so I'm sitting on that :-) Windows SetThreadLocale and CRT setlocale[^]
-
Hey, thanks :-) But "English" doesn't return "English (United States)", but generic English. Anyway, I found this GREAT article in codeproject that sort some things out, so I'm sitting on that :-) Windows SetThreadLocale and CRT setlocale[^]
-
Green Fuze wrote:
But "English" doesn't return "English (United States)"
Try "English_US". I know locales sometimes seem far more complicated than necessary but there are many different combinations to account for.
It's time for a new signature.
It seems that "american_US" in ::setlocale and 1033 for ::SetThreadLocale() done the trick :-) . It is far too complicated than it should've been! Thanks again! :-)
-
Hey everybody I have the following code:
wstring curlocale1(::_wsetlocale(LC_ALL, NULL));
printf("+++ current locale: %s", curlocale1.c_str());::_wsetlocale(LC_ALL, L"en_us");
wstring curlocale2(::_wsetlocale(LC_ALL, NULL));
printf("+++ current locale: %s", curlocale2.c_str());and the output is: +++ current locale: C +++ current locale: C I can't understand why my locale does not change, what am I doing wrong? Thanks a lot!
Locales are platform dependent. They're the most irritating bit of the C++ standard as they leave the likes of Redmond and the Penguin crowd to make the decisions. And they're usually different. I'm not surprised that your code is going horribly wrong on another level - using printf %s with a wide character string is a recipe for printing the first character out if I've ever seen one. Cheers, Ash
-
It seems that "american_US" in ::setlocale and 1033 for ::SetThreadLocale() done the trick :-) . It is far too complicated than it should've been! Thanks again! :-)