int main()
{
char str[200] = {0};
char out[500] = {0};
str[0]=0x00; str[1]=0x52; str[2]=0x00; str[3]=0x65; str[4]=0x00; str[5]=0x73; str[6]= 0x00; str[7]=0x74;
for(int i=0;i<sizeof(str);i++)
cout<<"-"<<str[i];
changeCharEncoding("UCS-2","ISO8859-1",str,out,sizeof(out));
cout<<"\noutput : "<<out;
for(int i=0;i<sizeof(out);i++)
cout<<":"<<out[i];
}
//encoding function
int changeCharEncoding(const char *from_charset, const char *to_charset, const char *input, char *output, int out_size)
{
size_t input_len = 8;
size_t output_len = out_size;
iconv_t l_cd;
if ((l_cd = iconv_open (to_charset, from_charset)) == (iconv_t) -1)
{
return -1;
}
int rc = iconv(l_cd, (char **)&input, &input_len, (char **)&output, &output_len);
if (rc == -1)
{
iconv_close(l_cd);
return -2;
}
else
{
iconv_close(l_cd);
}
}
请建议我一种将 16 位数据转换为 8 位的方法。我已经使用 iconv 尝试过。如果还有其他事情可以做同样的事情,也建议我。