How to print UTF16 in C++

And this, is why I hate working with C++

Why does this have to be so damn hard? It took hours to narrow down this information, and even then it’s pretty platform specific. Iconv is open source, but who’s going to want to download an entire library just to convert UTF16 to UTF8 on windows? No one, thats who.

#include <iconv.h>
char dst[100];
memset(dst, 0, sizeof(dst));

size_t dstlen = sizeof(dst);
size_t srclen = N_BYTES_IN_UTF16_POINTER;

char * pIn = (char*)(YOUR_UTF16_POINTER);
char * pOut = dst;

iconv_t conv = iconv_open("UTF-8", "UTF-16");
size_t retn = iconv(conv, &pIn, &srclen, &pOut, &dstlen);

std::cout << "CONVERTED " << dst << endl;

And the documentation can be easily located with a quick google search (/sarcasm/) and found here:

Leave a Reply

Your email address will not be published. Required fields are marked *