1 2 3 4 5 6 7 8 9 10 11 12 13
| std::string narrow(const std::wstring& ws , std::locale loc = std::locale("") )
{
std::vector<char> temp( ws.length() );
std::use_facet< std::ctype<wchar_t> >(loc).narrow( ws.data() , ws.data()+ws.length(), '?', &temp[0]);
return std::string(temp.begin(),temp.end());
}
std::wstring widen(const std::string& s, std::locale loc = std::locale(""))
{
std::vector<wchar_t> temp( s.length() );
std::use_facet< std::ctype<wchar_t> >(loc).widen( s.data() , s.data()+s.length(), &temp[0]);
return std::wstring(temp.begin(),temp.end());
} |