3

我正在尝试使用 allegro 运行以下代码。

textout_ex(屏幕、字体、numbComments 、100、100、绿色、黑色);

numbComments 是一个整数,这个函数的函数原型是

  void textout_ex(BITMAP *bmp, const FONT *f, const char *s, 
                                      int x, int y, int color, int bg);

根据我的理解,我不能在第三位传递这个整数。

因此,我需要将整数转换为 char*s。

请帮忙?

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

4

3 回答 3

2

Str是一个std::stringtextout_ex需要一个const char*. 用于Str.c_str()从 中检索 Cconst char*数据格式Str

于 2010-04-25T21:59:56.380 回答
1

textout_ex期望 a const char*,而你的Str是 a ,string尝试调用textout_exStr.c_str();

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

于 2010-04-25T22:01:56.803 回答
0

像这样使用textprintf_ex

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

它就像printf()一样工作。

于 2010-04-26T20:12:24.050 回答