I’ve read Stroustrup’s Appendix D (particular attention to Locales and Codecvt). Stroustrup does not give a good codecvt and widen example (IMHO). I’ve been trying to knob turn stuff from the internet with no joy. I’ve also tried imbue’ing stringstreams without success.
Would anyone be able to show (and explain) the code to go from a UTF-8 to a UTF-16 (or UTF-32) encoding? NOTE: I do not know the size of the input/output string in advance, so I expect the solution should use reserve and a back_inserter. Please don’t use out.resize(in.length()*2).
When finished, it would be great if the code actually worked (its amazing how much broken code is out there). Please make sure the following ’round trips’. The bytes below are the Han character for ‘bone’ in UTF-8 and UTF-{16|32}.
const std::string n("\xe9\xaa\xa8");
const std::wstring w = L"\u9aa8";
My apologies for a basic question. On Windows, I use the Win32 API and don’t have these problems moving between encodings.
It seems pretty obvious that he was smoking weed. As for the codepage conversions, look no further than iconv!