// string<——>wstring
#include <codecvt>
std::string wstring2utf8string(const std::wstring& str)
{
static std::wstring_convert<std::codecvt_utf8<wchar_t> > strCnv;
return strCnv.to_bytes(str);
}
std::wstring utf8string2wstring(const std::string& str)
{
static std::wstring_convert<std::codecvt_utf8<wchar_t> > strCnv;
return strCnv.from_bytes(str);
}
// wtring——>wchar\nwstring.c_str()
// 如:vector<string> 转wchar
std::vector<std::string> titleList = {"name","P4","Ms","P2","T2","P5","T5"};
utf8string2wstring(titleList[i]).c_str();
// 在BasicExcel中,不能直接将base_string类型给单元格赋值,则需要进行类型转换"
标签:02,编码,string,C++,wstring,std,static,str,strCnv
From: https://www.cnblogs.com/dbai/p/17187658.html