wstring和string互相转换
摘自大佬
string转wstring
#include<iostream>
#include<locale>
#include<vector>
#include<string>
using namespace std;
wstring to_wstring(const string& str, const locale& loc = locale())
{
vector<wchar_t>buf(str.size());
use_facet<ctype<wchar_t>>(loc).widen(str.data(), str.data() + str.size(), buf.data());
return wstring(buf.data(), buf.size());
}
wstring转换string
string to_string(const wstring& str, const locale& loc = locale())
{
vector<char>buf(str.size());
use_facet<ctype<wchar_t>>(loc).narrow(str.data(), str.data() + str.size(), '*', buf.data());
return string(buf.data(), buf.size());
}