How about trying like this:-
std::string s = u8"Your string";
// #include <codecvt>
std::wstring_convert<std::codecvt<char16_t,char,std::mbstate_t>,char16_t> convert;
std::u16string u16 = convert.from_bytes(s);
std::string u8 = convert.to_bytes(u16);
Also check this for UTF to UTF conversion.
From the docs:-
The specialization codecvt converts between
the UTF-16 and UTF-8 encoding schemes, and the specialization
codecvt converts between the UTF-32 and
UTF-8 encoding schemes.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…