【问题标题】:convert int to string for use in allegro function将 int 转换为字符串以用于 allegro 函数
【发布时间】:2010-04-25 21:53:43
【问题描述】:

我正在尝试使用 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。

请帮忙?

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

【问题讨论】:

  • allegro.cc/manual/api/text-output/textout_ex - 在位图上写入一个字符串。
  • 我看到答案是一样的,但我还是不明白该放什么,请你复制我粘贴的整个代码,或者更简单地解释一下

标签: c++ allegro


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    textout_ex 需要 const char*,而您的 Strstring,请尝试使用 Str.c_str(); 调用 textout_ex

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

    【讨论】:

    • 我看到答案是一样的,但我还是不明白该放什么,请你复制我粘贴的整个代码,或者更简单地解释一下
    • thanx,但是,函数原型已经设置好了,我没有做,不认为我可以访问它吗?另外,我希望将字符放入代码中其他位置的函数中。有没有办法将我的整数转换为需要的整数?
    【解决方案3】:

    使用textprintf_ex 喜欢:

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

    它就像printf() 一样工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-23
      • 2011-10-02
      • 2011-03-06
      • 1970-01-01
      • 2018-07-05
      相关资源
      最近更新 更多