此代码使用 Visual C++ 11 进行编译,并在 Windows 7 上按预期运行,但无法使用 Windows 7 上的 MinGW 4.7.0 或 Linux 上的 gcc 4.8.0 进行编译。编译用-std=c++11
flag
#include <codecvt>
#include <string>
// convert UTF-8 string to wstring
std::wstring utf8_to_wstring (const std::string& str)
{
std::wstring_convert<std::codecvt_utf8<wchar_t>> myconv;
return myconv.from_bytes(str);
}
// convert wstring to UTF-8 string
std::string wstring_to_utf8 (const std::wstring& str)
{
std::wstring_convert<std::codecvt_utf8<wchar_t>> myconv;
return myconv.to_bytes(str);
}
Error:
codecvt:没有这样的文件或目录。
GCC 拒绝这段代码的原因很简单:libstdc++ 不支持<codecvt>
yet.
The C++11 支持状态页面 http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.2011证实了这一点:
22.5 标准代码转换面N
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)