codecvt不是std头吗? [英] Is codecvt not a std header?

查看:2531
本文介绍了codecvt不是std头吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码使用Visual C ++ 11编译并在Windows 7上按预期运行,但无法使用Windows 7上的MinGW 4.7.0或Linux上的gcc 4.8.0编译。编译 -std = c ++ 11 标志

This code compiles with Visual C++ 11 and runs as expected on Windows 7 but fails to compile using either MinGW 4.7.0 on Windows 7 or gcc 4.8.0 on Linux. Compiling with -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);
}

错误:

codecvt:没有此类文件或目录。

codecvt: No such file or directory.


推荐答案

GCC拒绝此代码的原因很简单:libstdc ++不支持< codecvt>

The reason why GCC rejects this code is simple: libstdc++ doesn't support <codecvt> yet.

a href =http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.2011> C ++ 11支持状态页确认:

The C++11 support status page confirms this:


22.5标准代码转换方面N

22.5 Standard code conversion facets N

这篇关于codecvt不是std头吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆