在linux上运行的结果:
root @ dt hero _ cn :/home/yiyou/go path/CPP test # g-otestasctestasc.CPP
root @ dt hero _ cn :/home/yiyou/go path/CPP test #./testasc
in1=我们aA,strlen(in1 )=8
in2=我们aA,strlen(in2 )=8
-26 -120 -111 -28 -69 -84 97 65
fffff E6 ffffff 88 fffff 91 f fffff E4 fffffbbffffac 6141
rec=0,strlen(out )=6
-50 -46 -61 -57 97 65
ffffffcefffffd2ffffff C3 ffffffc 76141
rec1=0,strlen(out1)=8
-26 -120 -111 -28 -69 -84 97 65
fffff E6 ffffff 88 fffff 91 f fffff E4 fffffbbffffac 6141
s1=aA,S1.size (=18,6
s2=我们aA,S2.size (=14,8
-26 -120 -111 -28 -69 -84 97 65 10
fffff E6 ffffff 88 fffff 91 f fffff E4 fffffbbffffac 6141 a
c代码:
#包含
#包含
#包含
#包含
using namespace std;
//编码转换
intcode _ convert (char * from _ charset,char *to_charset,char *inbuf,size_t inlen,char *outbuf,size_t
{
iconv_t cd;
int rc;
char **pin=inbuf;
char **pout=outbuf;
CD=iconv_open(to_charset,from_charset );
if(CD==0)返回- 1;
if(iconv(CD,pin,inlen,pout,outlen )=-1 ) return -1;
iconv_close(CD );
返回0;
}
//utf8代码为GB2312jydgb/pintU2g(char*inbuf,int inlen,char *outbuf,int outlen ) ) ) ) ) ) ) )
{
returncode_convert('utf-8 ',' gb2312 ',inbuf,inlen,outbuf,outlen );
}
//从//GB2312代码迁移到utf8
intG2U(char*inbuf,size_t inlen,char *outbuf,size_t outlen ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) )
{
returncode_convert(GB2312、utf-8、inbuf、inlen、outbuf、outlen );
}
//utf8迁移到gbk
stringu2a(constchar*inbuf ) ) ) ) ) ) ) ) ) ) ) ) ) stringu2a(constchar*inbuf ) ) ) ) )
{
intinlen=strlen(inbuf;
字符串字符串;
srret.resize(Inlen*22 );
if (' utf-8 '、' gbk '、const_cast(inbuf )、inlen、strRet[0]、strRet.size ) )
return inbuf;
return strRet;
}
//gbk迁移到utf8
StringA2U(Constchar*inbuf ) ) ) ) ) ) ) ) ) ) ) ) ) stringa 2u ) ) ) ) ) char * inbuf ) ) ) ) ) 652 )
{
intinlen=strlen(inbuf;
字符串字符串;
srret.resize(Inlen*22 );
if(code_convert(gbk )、utf-8 )、const_cast(inbuf )、inlen、strRet[0]、strRet.size ) )
return inbuf;
return strRet;
}
#define OUTLEN 255
void test_u2g_g2u (
{
char *in1='我们aA ';
char * in2='xe6x88x91xe4xbbxacx61x41 ';
printf(in1=%s,strlen(in1 )=%dn ),in1,strlen(in1 );
printf(in2=%s,strlen(in2 )=%dn ),in2,strlen(in2 );
for(intI=0; I
打印((n );
for(intI=0; I
打印((n );
char out[OUTLEN];
char out1[OUTLEN];
intrec=U2G(in1,strlen(in1 ),out,OUTLEN );
printf(rec=%d,strlen(out )=%dn ),rec,strlen(out ) );
for(intI=0; I
打印((n );
for(intI=0; I
打印((n );
intreC1=G2U(out,strlen(out ),out1,OUTLEN );
printf(rec1=%d,strlen(out1)=%dn ),reC1,strlen(out1);
for(intI=0; I
打印((n );
for(intI=0; I
打印((n );
stringS1=U2A(in1 );
stringS2=A2U(S1.C_str ) );
printf(S1=%s,s1.size ) (=%d,%dn ),s1.c_str ),s1.size ),strlen ) s1.c_str ) );
printf(S2=%s,s2.size ) (=%d,%dn ),s2.c_str ),s2.size ),strlen ) s2.c_str ) );
}
/*在内jydgb/p Windows下:
aA
97 65
61 41
-50 -46 -61 -57 97 65
ffffffcefffffd2ffffff C3 ffffffc 76141
汉字:我们aA
十六进制: CE D2 C3 C7 61 41
Private Sub Command1_Click (
msgboxhex$(ascw (我) ) (6211//windows大字jzdjb
msgboxHEX$(ASC (我) ) ) ced2//国标的
End心动的衣服/p http://www.program fan.com/club/show post.ASP? id=24101
3358 blog.csdn.net/black _ dragon/archive/2005/05/25/380638.aspx
root @ dt hero _ cn :/home/yiyou/go path/CPP test #./testasc
-26 -120 -111 -28 -69 -84 97 65 10
fffff E6 ffffff 88 fffff 91 f fffff E4 fffffbbffffac 6141 a
root @ dt hero _ cn :/home/yiyou/go path/CPP test #./testasc
-26 -120 -111 10
ffffffe6 ffffff88 ffffff91 a
int main () )
{
test_u2g_g2u ();
char s[80]={0};
int i=0,n=0;
//while(1) {
fets(s,100,stdin );
n=Strlen(s;
//if(n==0) break;
for(I=0; I
打印((n );
for(I=0; I
打印((n );
//}
//getchar (;
返回0;
}