简体   繁体   中英

UTF-8 to C/POSIX locale conversion using iconv() fails

I am trying to convert UTF-8 string to C/POSIX locale string
The UTF-8 string is "abc123£" (in bash "abc123\\302\\243"`)

  1. iconv_open("", "UTF-8"); // "" means default program locale ie C
  2. iconv_open("UCS-2LE", "UTF-8");

iconv() is returning EILSEQ to me in case 1, but success in case 2.

What is the reason for this?
Also, how can I successfully convert any UTF-8 string to 'C' locale string.

因为您的C语言环境使用的字符集(可能是US-ASCII)没有用于£的字符,并且不能无损地转换字符串。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM