这段代码在 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:没有这个文件或目录。