Is codecvt not a std header?

前端 未结 4 800
清酒与你
清酒与你 2020-12-03 00:41

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

相关标签:
4条回答
  • 2020-12-03 01:19

    The question was asked almost 3 years ago and I was surprised that I am also having same issue using Ubuntu 14.04 with fresh updates.

    Second surprise, the link provided by @Fanael shows now:

    22.5 Standard code conversion facets Y

    So I searched which version of GCC would fully implement C++11. Turns out that full support was added in GCC 5:

    https://gcc.gnu.org/gcc-5/changes.html

    Full support for C++11, including the following new features:

    ...

    locale facets for Unicode conversion;

    ...

    I would have been happy to put a comment on the answer if I had enough reputation :)

    0 讨论(0)
  • 2020-12-03 01:19

    It works on Ubuntu 14.04 with gcc 5.3.

    0 讨论(0)
  • 2020-12-03 01:20

    A workaround using Boost.Locale:

    #include <boost/locale/encoding_utf.hpp>
    #include <string>
    
    using boost::locale::conv::utf_to_utf;
    
    std::wstring utf8_to_wstring(const std::string& str)
    {
        return utf_to_utf<wchar_t>(str.c_str(), str.c_str() + str.size());
    }
    
    std::string wstring_to_utf8(const std::wstring& str)
    {
        return utf_to_utf<char>(str.c_str(), str.c_str() + str.size());
    }  
    
    0 讨论(0)
  • 2020-12-03 01:21

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

    The C++11 support status page confirms this:

    22.5 Standard code conversion facets N

    0 讨论(0)
提交回复
热议问题