I'm looking for a bit of advice on the best way to convert a
If you are not interested in the semantic of the content, but just to the content to be comparable, I'll just coherce the inner wchar into a char of doubled size and use it to initialize the string (by specifying address/size in the constructor)
std::wstring ws(L"ABCD€FG"); std::string s((const char*)&ws, sizeof(wchar_t)/sizeof(char)*ws.size());
s is unprintable (it may contain null chars) but still assignable and comparable.
Yo can go back as:
std::wstring nws((const wchar_t*)&s, sizeof(char)/sizeof(wchar_t)*s.size());
std::cout << (nws==ws)
However, note that this way the order in the map (result of
operator<) is ... fuzzy because of the presence of the 0, and don't reflect any text sematics. However search still works, since -however fuzzy- it is still an "order".