Convert UTF-16 to UTF-8 under Windows and Linux, in C

前端 未结 8 735
不思量自难忘°
不思量自难忘° 2020-12-01 02:50

I was wondering if there is a recommended \'cross\' Windows and Linux method for the purpose of converting strings from UTF-16LE to UTF-8? or one should use different method

8条回答
  •  Happy的楠姐
    2020-12-01 03:32

    #include 
    
    wchar_t *src = ...; // or char16_t* on non-Windows platforms
    int srclen = ...;
    char *dst = ...;
    int dstlen = ...;
    iconv_t conv = iconv_open("UTF-8", "UTF-16");
    iconv(conv, (char*)&src, &srclen, &dst, &dstlen);
    iconv_close(conv);
    

提交回复
热议问题