把int转换为char*然后输出,这么简单得东西我的编译器不通过?不知道是我傻了还是机子傻了~
我需要用TextOut()函数,输出一段字符串,包括了字符和数字
我先写一个定义
char *ss;
int D=999;
然后
ss="this is a temp:";
最后要把999这个数字加在上面这串字符后面,然后再加上一段字符,看起来好简单
我试了N种方法,包括strcpy,memcpy,还有ostrstream(ss,3)<<D<<endl;
居然都编译报错,我都晕了~~
哪位大哥给指点下吧~
问题点数:20、回复次数:4Top
1 楼steedhorse(晨星)回复于 2005-04-03 18:17:39 得分 5
方法1:
char s[64] = "this is a temp:";
char tmp[8];
strcat(s, itoa(999, tmp, 10));
方法2:
char tmp[8];
string s = this is a temp;
s += itoa(990, tmp, 10);
方法3:
char s[] = "this is a temp:";
char s1[64];
sprintf(s1, "%s%d", s, 999);
方法4:
CString s = "this is a temp:";
s += itoa(990, tmp, 10);
方法5:
char s[] = "this is a temp:";
CString s1;
s1.Fromat("%s%d", s, 999);Top
2 楼yhz(耗子)回复于 2005-04-03 18:18:03 得分 5
sprintf(ss, "this is a temp:%d", D);
Top
3 楼tankbattle(坦克大战)回复于 2005-04-03 18:18:59 得分 5
char Buffer[100];
sprintf(Buffer, "%s%d", ss, D);Top
4 楼steedhorse(晨星)回复于 2005-04-03 18:19:22 得分 5
看你的需求,还不如干脆就这样:
char s[64];
sprintf(s, "this is a temp:%d", 999);
或者:
CString s;
s.Format("this is a temp:%d", 999);Top




