Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert int to string for use in allegro function

Tags:

c++

allegro

I am trying to run the following code using allegro.

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

numbComments is an integer, the function prototype 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 pass this integer in the third position.

I therefore need to convert the integer into a char*s.

Help please?

i cannot, of course, change the actual function prototype

like image 308
ace Avatar asked Dec 21 '25 07:12

ace


2 Answers

Str is a std::string. textout_ex requires a const char*. Use Str.c_str() to retrieve the C const char* data format from Str.

like image 171
Potatoswatter Avatar answered Dec 23 '25 19:12

Potatoswatter


textout_ex expects a const char*, and your Str is a string, try calling textout_ex with Str.c_str();

Edit: Applied to your code : textout_ex(screen, font, Str.c_str(), 100, 100, GREEN, BLACK);

like image 30
Soufiane Hassou Avatar answered Dec 23 '25 21:12

Soufiane Hassou