如何进行反向转换

时间:2016-04-24 15:48:04

标签: c++ c++11 utf-8 wstring

为了将std::wstring转换为UTF-8,我使用以下代码:

std::wstring my_wide_string = L"my_sqlite_db.db";
std::wstring_convert<std::codecvt_utf8<wchar_t> > myconv;
myconv.to_bytes( my_wide_string.c_str() );

现在,我需要进行后向转换,即UTF-8到std::wstring

切换转换器的正确方法是什么?

1 个答案:

答案 0 :(得分:1)

为什么不使用from_bytes()反向函数:

std::wstring test = myconv.from_bytes(myutf8);

Live demo