toupper / tolower + locale(german) [英] toupper/tolower + locale (german)
问题描述
如何将字符串(wstring)从小写字符转换为大写字符,反之亦然?
我搜索的网络,发现有一个STL函数std ::变换。
但是直到现在我hav'nt想出了如何给正确的locale对象,例如Germany_german到函数。
谁可以帮助吗?
我的代码如下:
wstring strin = LABCÄÖÜabcäöü;
wstring str = strin;
locale loc(Germany_german); // ???如何应用此???
std :: transform(str.begin(),str.end(),str.begin(),(int(*)(int)tolower);
// result:abcäöüabcäöü
字符ÄÖÜ和äöü(它就像Ae,Oe,Ue) p>
PS:我不喜欢大开关汗水,而且我知道BOOST有能力的一切,我更喜欢STL解决方案。 p>
提前感谢
糟糕
你在Unix,看到 / usr / share / locale /
可用的语言环境看起来你想要de_DE.UTF-8 / code>。
但是 setlocale(LC_ALL,);
如果我只是像这样设置默认语言环境,那么你的程序适用于我(我固定了一个闭函数),而不指定德国。
how to convert a string (wstring) from lowercase to uppercase characters and vice versa?
I searched the net and found there is a STL-function std::transform.
But until now I hav'nt figured out how to give the right locale-object for example "Germany_german" to the function.
Who can help please?
my code looks like:
wstring strin = L"ABCÄÖÜabcäöü";
wstring str = strin;
locale loc( "Germany_german" ); // ??? how to apply this ???
std::transform( str.begin(), str.end(), str.begin(), (int(*)(int)tolower );
//result: "abcäöüabcäöü"
The characters ÄÖÜ and äöü (it's like Ae, Oe, Ue) will not be converted correctly.
P.S.: I don't prefer a big switch sweat and also I know BOOST is capable of everything, i would prefer a STL solution.
thanks in advance
Oops
If you're on Unix, see /usr/share/locale/
for available locales. It looks like you want "de_DE.UTF-8"
.
But setlocale(LC_ALL, "");
should set the program to work in the system's locale, whatever it is.
Your program works for me (I fixed a close-paren) if I simply set the default locale like that, without specifying Germany.
这篇关于toupper / tolower + locale(german)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!