我们如何在 C 或 C++ 中将多语言字符串或 unicode 字符串转换为大写/小写。
如果您的系统已经采用 UTF-8,请使用std::use_facet http://en.cppreference.com/w/cpp/locale/use_facet, 你可以写:
#include <iostream>
#include <locale.h>
int main() {
std::locale::global(std::locale("")); // (*)
std::wcout.imbue(std::locale());
auto& f = std::use_facet<std::ctype<wchar_t>>(std::locale());
std::wstring str = L"Zoë Saldaña played in La maldición del padre Cardona.";
f.toupper(&str[0], &str[0] + str.size());
std::wcout << str << std::endl;
return 0;
}
你得到(http://ideone.com/AFHoHC http://ideone.com/AFHoHC):
佐伊·萨尔达尼亚 (ZOË SALDAÑA) 曾在《卡多纳神父》中效力。
如果它不起作用,你将不得不改变(*) into std::locale::global(std::locale("en_US.UTF8"));
或者您在平台上实际拥有的 UTF-8 语言环境。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)