Convert int to string for use in allegro function

I am trying to run the following code using allegro.

textout_ex (screen, font, numbComments, 100, 100, GREEN, BLACK);

numbComments is an integer, the prototype of the function of this function is

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

and I cannot, according to my understanding, transfer this integer to the third position.

So I need to convert an integer to char * s.

Help me please?

I cannot, of course, change the prototype of the actual function

+3
source share
3 answers

Stris std::string. textout_exrequired a const char*. Use Str.c_str()to obtain data format C const char*s Str.

+2
source

textout_ex const char*, Str - string, textout_ex Str.c_str();

Edit: : textout_ex(screen, font, Str.c_str(), 100, 100, GREEN, BLACK);

+1

textprintf_ex :

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

It works the same as printf () .

0
source

Source: https://habr.com/ru/post/1742712/


All Articles