Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is codecvt not supported by Clang or GCC?

I can't even get the basic codecvt example from cppreference.com:

// codecvt_utf8_utf16 example
#include <iostream>
#include <locale>
#include <string>
#include <codecvt>

int main ()
{
  std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,char16_t> conversion;
  std::string mbs = conversion.to_bytes( u"\u4f60\u597d" );  // ni hao (你好)

  // print out hex value of each byte:
  std::cout << std::hex;
  for (int i=0; i<mbs.length(); ++i)
    std::cout << int(unsigned char(mbs[i])) << ' ';
  std::cout << '\n';

  return 0;
}

...to compile on GCC 4.9 or Clang 3.4.

like image 644
Chris_F Avatar asked Dec 11 '25 10:12

Chris_F


1 Answers

According to libstdc++ manual, part 22.4.1, it is missing the support for codecvt, even on the latest version.

And libc++ has complete support for C++11 and C++14 features, so you should use it on CLang, specifying the -stdlib=libc++ compiler flag (make sure you have it installed).

Edit: As of current versions of libstdc++, codecvt is now supported.

like image 113
Bruno Ferreira Avatar answered Dec 14 '25 06:12

Bruno Ferreira



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!