将int转换为用于allegro函数的字符串
问题描述:
我正在尝试使用allegro运行以下代码。将int转换为用于allegro函数的字符串
textout_ex(screen,font,numbComments,100,100,GREEN,BLACK);
numbComments是整数, 该函数的函数原型是
void textout_ex(BITMAP *bmp, const FONT *f, const char *s,
int x, int y, int color, int bg);
,我无法,根据我的理解通过在第三位置该整数。
因此我需要将整数转换为char * s。
请帮忙吗?
我不能,当然,改变实际函数原型
答
Str
是std::string
。 textout_ex
需要const char*
。使用Str.c_str()
从Str
检索C const char*
数据格式。
答
textout_ex
需要一个const char*
,和你的Str
是string
,尝试调用textout_ex
与Str.c_str();
编辑: 应用到你的代码: textout_ex(screen, font, Str.c_str(), 100, 100, GREEN, BLACK);
out.str()。c_str() – 2010-04-25 21:56:05
http://www.allegro.cc/manual/api/text-output/textout_ex - 在位图上写入一个字符串。 – Potatoswatter 2010-04-25 21:58:38
我看到答案是一样的,我仍然不明白要放什么,但是,请你可以复制我粘贴的更改或更简单地解释整个代码 – ace 2010-04-25 22:10:32