【发布时间】:2013-03-25 12:36:30
【问题描述】:
此代码使用 Visual C++ 11 编译并在 Windows 7 上按预期运行,但无法使用 Windows 7 上的 MinGW 4.7.0 或 Linux 上的 gcc 4.8.0 进行编译。使用-std=c++11 标志编译
#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);
}
错误:
codecvt:没有这样的文件或目录。
【问题讨论】:
-
请注意,已经实现 C++11 编解码器(例如 MSVC)的编译器很可能会被 C++17 论文弃用:open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0618r0.html。除非论文中的“其他方向”优先。