极简单问题,在线等待,100分相送
在SDK中怎么样将一个int,或long型的变量和一个字符串连接起来,然后用TextOut在窗口上显示出来
如int x=0;
for(x=0;x<10;x++)
{
TextOut(hdc, , );
}
在窗口上显示
the x=0
the x=1
the x=2
问题点数:100、回复次数:10Top
1 楼ksyou(过河卒:不能回头怎么办?)回复于 2003-04-01 15:08:42 得分 5
将int或者long用itoa函数转换为字符串Top
2 楼gufengduyu(孤独的呆呆龙)回复于 2003-04-01 15:10:04 得分 5
用格式化函数:sprintf(),和printf()用法一样
Top
3 楼skyzxg(sky)回复于 2003-04-01 15:11:23 得分 10
CString str;
for (int x = 0; x < 3; x++)
{
str.Format("the X = %d", x);
TextOut(hdc, 0 , str );
}Top
4 楼CowWu(老牛)回复于 2003-04-01 15:11:48 得分 10
将int或者long用itoa函数转换为字符串
用格式化函数:sprintf(),和printf()用法一样
CString.Format();
等等Top
5 楼xt_jat(桑巴)回复于 2003-04-01 15:13:57 得分 15
我通常这样用
#include <sstream>
for ( x=0; x<10; ++x )
{
std::stringstream s ;
s<<"the x="<<x ;
TextOut(hDC,,,s.str().c_str()) ;
}Top
6 楼happy__888([顾问团]寻开心 www.e-jjj.com)回复于 2003-04-01 15:16:20 得分 45
查看一下 sprintf 函数, 可以把任意类型的数据,格式化输出到字符串当中,然后显示字符串就可以了。
char str[512];
sprintf(str, "the x =%d", x);
或者是 MFC的 CString类的 Format函数也可以。
例如:
CString str;
str.Format("The x=%n", x);
TextOut(hdc, str);Top
7 楼lookingfor(水如我衣)回复于 2003-04-01 15:21:35 得分 0
用强制类型转换怎么样
(char) IntNumTop
8 楼tigerVC(Tiger.Z)回复于 2003-04-01 15:47:21 得分 5
用字符串的Format是很好的Top
9 楼timepalette(时间调色板)回复于 2003-04-01 20:24:26 得分 5
int x=1;
char *p = (char *)x;
while(1) p++;Top
10 楼night_cat(夜猫子)回复于 2003-04-01 20:58:18 得分 0
GZTop




