在vc中怎么样将int类型转化为cstring类型 demo:int aa = 12345;CString bb;bb.Format("%d", aa);MessageBox(bb); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 itoa将int转换成char*,让CString直接=char*就可以了 其它数据类型转换到CString使用CString的成员函数Format来转换,例如:整数(int)str.Format("%d",i); 浮点数(float)str.Format("%f",i); 字符串指针(char *)等已经被CString构造函数支持的数据类型可以直接赋值str = username; 应该是_itoa吧!例子看msdn #include <stdlib.h>#include <stdio.h>void main( void ){ char buffer[20]; int i = 3445; long l = -344115L; unsigned long ul = 1234567890UL; _itoa( i, buffer, 10 ); printf( "String of integer %d (radix 10): %s\n", i, buffer ); _itoa( i, buffer, 16 ); printf( "String of integer %d (radix 16): 0x%s\n", i, buffer ); _itoa( i, buffer, 2 ); printf( "String of integer %d (radix 2): %s\n", i, buffer ); _ltoa( l, buffer, 16 ); printf( "String of long int %ld (radix 16): 0x%s\n", l, buffer ); _ultoa( ul, buffer, 16 ); printf( "String of unsigned long %lu (radix 16): 0x%s\n", ul, buffer );}OutputString of integer 3445 (radix 10): 3445String of integer 3445 (radix 16): 0xd75String of integer 3445 (radix 2): 110101110101String of long int -344115 (radix 16): 0xfffabfcdString of unsigned long 1234567890 (radix 16): 0x499602d2 int nTest = 1111;CString sTest;nTest.Format("%d", sTest);//此时sTest就是"1111"//当然用 wmouse(山水)的也好,不过使用Format很方便,在VC代码中很多的 CString syt="123";int k=atoi(str); //转换k=123 itoa 是 转化为 char* 的 sprintfsprintf(string a,"%d",int b); 最简单的就是用CString的函数Format. 搞笑,呵呵,看错了!用format是最简单的:int k=123;CString str;str.Format("%d",k);str="123"; int a=10;CString b;b.Format("%d",a); 能不能将char类型的转化为整型 itoa int->stringatoi string->int看MSDN 请问如何实现指定时间间隔触发函数? 哪位大侠 帮我 分析下 如何用鼠标跟踪显示不同信息? 新年好,大家帮我看看关于遍历文件夹的问题 BHO 如何屏蔽网页中的不良信息?? LibUIDK全面降价 风格中的&与|运算 关于_MAX_PATH的疑问 为什么在TCP通讯里在报文中要有报文的长度这个项目? KFC对MFC的诉状——很搞笑的 绨(Twip 1/1440英寸)如何与厘米(CM)转换??? 用MFC向导生成的单文档程序, 子窗口都是3D风格的, 我如何才能去掉这些3D风格。比如说让View 与非客户区在一个平面上,不让view凹进去。
使用CString的成员函数Format来转换,例如:
整数(int)
str.Format("%d",i);
浮点数(float)
str.Format("%f",i);
字符串指针(char *)等已经被CString构造函数支持的数据类型可以直接赋值
str = username;
#include <stdlib.h>
#include <stdio.h>void main( void )
{
char buffer[20];
int i = 3445;
long l = -344115L;
unsigned long ul = 1234567890UL; _itoa( i, buffer, 10 );
printf( "String of integer %d (radix 10): %s\n", i, buffer );
_itoa( i, buffer, 16 );
printf( "String of integer %d (radix 16): 0x%s\n", i, buffer );
_itoa( i, buffer, 2 );
printf( "String of integer %d (radix 2): %s\n", i, buffer ); _ltoa( l, buffer, 16 );
printf( "String of long int %ld (radix 16): 0x%s\n", l,
buffer ); _ultoa( ul, buffer, 16 );
printf( "String of unsigned long %lu (radix 16): 0x%s\n", ul,
buffer );
}
OutputString of integer 3445 (radix 10): 3445
String of integer 3445 (radix 16): 0xd75
String of integer 3445 (radix 2): 110101110101
String of long int -344115 (radix 16): 0xfffabfcd
String of unsigned long 1234567890 (radix 16): 0x499602d2
CString sTest;nTest.Format("%d", sTest);//此时sTest就是"1111"
//当然用 wmouse(山水)的也好,不过使用Format很方便,在VC代码中很多的
int k=atoi(str); //转换k=123
sprintf(string a,"%d",int b);
CString str;
str.Format("%d",k);str="123";
CString b;
b.Format("%d",a);
看MSDN