将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。

请帮忙吗?

我不能,当然,改变实际函数原型

+0

out.str()。c_str() – 2010-04-25 21:56:05

+0

http://www.allegro.cc/manual/api/text-output/textout_ex - 在位图上写入一个字符串。 – Potatoswatter 2010-04-25 21:58:38

+0

我看到答案是一样的,我仍然不明白要放什么,但是,请你可以复制我粘贴的更改或更简单地解释整个代码 – ace 2010-04-25 22:10:32

Strstd::stringtextout_ex需要const char*。使用Str.c_str()Str检索C const char*数据格式。

textout_ex需要一个const char*,和你的Strstring,尝试调用textout_exStr.c_str();

编辑: 应用到你的代码: textout_ex(screen, font, Str.c_str(), 100, 100, GREEN, BLACK);

+0

我看到答案是一样的,我仍然不明白什么放在哪里,虽然,请你可以复制整个代码,我粘贴的变化或更简单地解释 – ace 2010-04-25 22:07:03

+0

在这里你去,回答更新:) – 2010-04-25 22:11:15

+0

thanx,但是,函数原型设置,我没有做到也不认为我有权访问它? 另外,我希望将字符放入代码中其他位置的函数中。 有没有办法只是将我的整数转换为需要? – ace 2010-04-25 22:14:26

使用textprintf_ex,如:

textprintf_ex(bmp, f, x, y, color, bg, "%d", numbComments);

它的工作原理就像printf()

+0

thanx但是什么是BG? – ace 2010-04-27 12:54:03

+0

背景颜色。 – Matthew 2010-04-27 16:32:31