下面的代码可以,貌似int型数有范围,超出则显示结果错误的字符串。
int x=1111111;
CString str;
str.Format("%i",x);
MessageBox(str);
————————itoa函数转换————————————
此函数头文件:stdlib.h
int n=123456789;
char str[10];
itoa(n,str,10)
//三个参数依次为:要转换的整型,转换后保存的char型,转换的基数(2,8,10,16)
cout<
cout<
运行结果:
123456789
1 2 3 4 5 6 7 8 9
int i = 100;
CString strID = "";
strID.Format("%d", i);
MessageBox(strID);
int型不能用MessageBox直接输出,一般是转换为字符串,然后输出。
char buf[]={0};
sprintf(buf,"%d",i);
MessageBox(NULL,buf,NULL,0);
int i = 123;
char tmp[8];
memset(tmp,0,8);
itoa(i,tmp,10);
MessageBox(NULL,tmp,"test",MB_OK);
itoa一下