Libiconv introduction in gblic

Source: Internet
Author: User
Libiconv in gblic-Linux general technology-Linux programming and kernel information. The following is a detailed description. With the development of web applications, we often need to convert the encoding format. Libiconv, which started with debian, can be applied on various platforms. This library is a good news for C/C ++ code, saving the trouble of code conversion. The shell has the iconv command, the specific usage is iconv-f UTF-8-t GBK from.txt-o to.txt. is encoded into GBK(to.txt ). this lib supports almost all encoding formats in the world, and is very powerful. However, it is important to note whether the two encoding formats define the text you want to convert. Otherwise, you will fail!

The header file of the library is included in iconv. h. The simple usage is as follows:

Char in_buf [1024];
Char out_buf [1024*2];
Char * in_ptr = in_buf;
Char * out_ptr = out_buf;

Cd = iconv_open ("UTF-8", "GB2312"); // convert the GB2312 character to the UTF-8

Iconv (cd, & in_ptr, (size_t *) & in_len, & out_ptr, (size_t *) & out_len );

Iconv_close (cd );

The common error is illegal input sequence at position. This indicates that the string you provide is not the encoding format to be converted, or you contain text not included in the character set. For example, if you use the Chinese characters in GBK as GB2312, the conversion will fail.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.