jeudi 24 novembre 2016

Decode utf8 entities from json into utf8 C++

I have a string with utf8 entities (I'm not sure I named it right):

std::string std = "\u0418\u043d\u0434\u0435\u043a\u0441";

How could I convert it into something more readable? I use g++ with C++11 support, but after couple of hours digging in std::codecvt manual I get no result:

std::string std = "\u0418\u043d\u0434\u0435\u043a\u0441";

wstring_convert<codecvt_utf8_utf16<char16_t>,char16_t> convert; 
string dest = convert.to_bytes(std); 

returns nightmare stacktrace started with:

error: no matching function for call to ‘std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>::to_bytes(std::string&)

I home there is another way.

Aucun commentaire:

Enregistrer un commentaire