I have to deal with std::wstring encoded in unicode. I need to be able to convert is to std::string (wchar_t -> char). So far, I've tried std::wstring_convert<std::codecvt_utf8<wchar_t> > but it throws a range error indicating that the conversion "failed" (whatever that's supposed to mean).
I have been at this for over a day now and I havn't been able to find anything on it. I've only found that this is supposed to work, but obviously does not. "failed" is extremely cryptic, and doesn't tell me anything, so I don't know what to do here.
Is there anyone who can show me how to convert Unicode-encoded std::wstrings to a plain std::string?
I figured it out... For my test cases, I was generating random wstrings with wchar_ts that had values between 0, and std::numeric_limits<wchar_t>::max(), and apparently, once I limited the values to a max of 0xfff it worked.
Now I have another question: is there a place I can find the max/min supported unicode characters? Or maybe you know a better why to convert unicode wstrings -> strings that doesn't blow up when given a value "out of range"?
The big problem is that I can enter values far greater than wchar_t in my text box, so this is a problem I need to solve. (in linux, ctrl+shift+U would allow me to enter any number I want, thus screwing up things...)