来源:https://zplutor.github.io/2016/07/03/convert-character-encoding-using-std-wstring-convert/ 文档:https://en.cppreference.com/w/cpp/locale/wstring_convert
C++11新增的std::wstring_convert可以很方便地在std::string和std::wstring之间进行转换。
string to wstring: from_bytes()
#include <codecvt>
#include <locale>
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
std::wstring wide_string = converter.from_bytes("\xe5\xad\x97\xe7\xac\xa6\xe4\xb8\xb2”); //字符串的内容为“字符串”
wstring to string: to_bytes()
#include <codecvt>
#include <locale>
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
std::string string = converter.to_bytes(L"这是一个宽字符串");