Hello, I'm trying to convert a C++ string to a wstring. I found the following code, that seems to deal with accents, which is what I'm looking for.
std::wstring widen(const std::string& s)
{
std::vector<wchar_t> buffer(s.size());
std::locale loc("fr_FR");
std::use_facet< std::ctype<wchar_t> >(loc).widen(s.data(), s.data() + s.size(), &buffer[0]);
return std::wstring(&buffer[0], buffer.size());
}
Unfortunately, the code crashes for any other loc value than C or POSIX. This problem has already been discussed, without success, here: http://stackoverflow.com/questions/1745045/stdlocale-breakage-on-macos-10-6-with-langenus-utf-8, here or here.
Is there any workaround or an other way to do this ?