Convert wstring to string encoded in UTF-8

前端 未结 6 1087
囚心锁ツ
囚心锁ツ 2020-11-29 04:19

I need to convert between wstring and string. I figured out, that using codecvt facet should do the trick, but it doesn\'t seem to work for utf-8 locale.

My idea is,

6条回答
  •  抹茶落季
    2020-11-29 04:32

    The Lexertl library has an iterator that lets you do this:

    std::string str;
    str.assign(
      lexertl::basic_utf8_out_iterator(wstr.begin()),
      lexertl::basic_utf8_out_iterator(wstr.end()));
    

提交回复
热议问题