문제

I am working on porting some legacy C++ code to Android platform. While doing so, I noticed that the code uses iconv_xxx() routines to deal with Unicode conversions. It so happens that Android NDK does not have iconv.h by default. I can download and build the source code for libiconv. However, I am just wondering why would one even bother using iconv_xxx functions when C++ compilers on almost all platforms support mbstowcs, wcstombs. and the related routines. Do iconv_xxx functions offer any advantage over mbsXXXwbsXXX routines? Regards.

도움이 되었습니까?

해결책

The mb/wc functions convert between the wchar_t encoding, which is platform-specific, and the multibyte encoding, which is platform and locale-specific.

On Linux on x86, wc is likely to be UTF-32LE and mb is most likely, but far from guaranteed, to be UTF-8. On Windows, wc is UTF-16LE; mb is likely to be the machine's default locale (ANSI) code page and vanishingly unlikely to be UTF-8.

So if you want to convert to or from known, specific encodings, you have to use iconv().

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top