1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
   |  
#include <string>
#include <locale>
 
std::string narrow(const std::wstring& ws) {
  std::string sResult; sResult.resize(ws.length());
  std::locale l("english");
  std::use_facet< std::ctype<wchar_t> >(l).narrow(&ws[0], &ws[ws.length()], '?', &sResult[0]);
  return sResult;
}
 
std::wstring widen(const std::string& s) {
  std::wstring wsResult; wsResult.resize(s.length());
  std::locale l("english");
  std::use_facet< std::ctype<wchar_t> >(l).widen(&s[0], &s[s.length()], &wsResult[0]);
  return wsResult;
} | 
Partager