【发布时间】:2018-01-16 14:50:07
【问题描述】:
在装有 Visual Studio 2017 的 Windows 上,我可以使用以下代码将 u32string 大写(基于 char32_t):
#include <locale>
#include <iostream>
#include <string>
void toUpper(std::u32string& u32str, std::string localeStr)
{
std::locale locale(localeStr);
for (unsigned i = 0; i<u32str.size(); ++i)
u32str[i] = std::toupper(u32str[i], locale);
}
同样的事情不适用于 macOS 和 XCode。 我收到这样的错误:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__locale:795:44: error: implicit instantiation of undefined template 'std::__1::ctype<char32_t>'
return use_facet<ctype<_CharT> >(__loc).toupper(__c);
有便携的方法吗?
【问题讨论】:
-
感觉你错过了
#include。没有minimal reproducible example,很难分辨。 -
我不认为我错过了一个头文件。我已将包含添加到示例中。
-
也许您的编译器的 RTL 根本没有实现
ctype<char32_t>?附带说明一下,这似乎是您应该使用std::transform()而不是手动循环的东西,例如:std::locale loc(localeStr); std::transform(u32str.begin(), u32str.end(), u32str.begin(), [&loc](char32_t c) -> char32_t { return std::toupper(c, loc); }); -
我想是的。有没有更好的(便携式)方法?
-
关于这个:stackoverflow.com/a/41316811/2007933 似乎不支持
ctype<char32_t>
标签: c++ c++11 unicode uppercase ctype