I also ran into this problem, I solve it using the upgrade locale library
try { std::string utf8 = boost::locale::conv::utf_to_utf<char, short>( (short*)wcontent.c_str(), (short*)(wcontent.c_str() + wcontent.length())); content = boost::locale::conv::from_utf(utf8, "ISO-8859-1"); } catch (boost::locale::conv::conversion_error e) { std::cout << "Fail to convert from UTF-8 to " << toEncoding << "!" << std::endl; break; }
The function boost :: locale :: conv :: utf_to_utf tries to convert from a buffer that is encoded by UTF-16LE to UTF-8, The function boost :: locale :: conv :: from_utf tries to convert from a buffer that is encoded by UTF-8 to ANSI, make sure the encoding is correct (here I use the encoding for Latin-1, ISO-8859-1).
Another reminder: on Linux, std :: wstring is 4 bytes long, but on Windows, std :: wstring is 2 bytes long, so it’s best not to use std :: wstring to store the UTF-16LE buffer.
Daniel King Dec 04 '13 at 4:37
source share