c++ - Convert std::basic_string<wchar_t> and std::basic_string<uint16_t> -


in macos x 10.10 clang:

typedef basic_string<char, char_traits<char>, allocator<char> > string; typedef basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> > wstring; 

i build string like: std::wstringstream ss;

ss << "["; ss << "{"; ss << "x1:" << 111 << ","; ss << "z1:" << 111; ss << "},"; ss << "{"; ss << "x2:" << 222 << ","; ss << "z2:" << 222; ss << "}"; ss << "]"; std::wstring str = ss.str(); 

and need pass str argument function expects std::basic_string<uint16_t> , returns string of same type.

how conversion between std::basic_string<wchar_t> , std::basic_string<uint16_t> make use of external library function?

c++11 allowed.

maybe use of wstring_convert or workaround?

first of need sure, source std::basic_string<wchar_t> has same encoding input std::basic_string<uint16_t>. if encoding different should specific character encoding conversion algorithm. otherwise can this.

std::basic_string<uint16_t> result; std::copy(source.begin(), source.end(), std::back_inserter(result)); 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -