3

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

ace
  • 189
  • 1
  • 1
  • 9
  • http://www.allegro.cc/manual/api/text-output/textout_ex - Writes a string on a bitmap. – Potatoswatter Apr 25 '10 at 21:58
  • I see the answer is the same, i still dont understand what to put where though, please can you copy the whole code that i pasted with the changes or explain more simply – ace Apr 25 '10 at 22:10

3 Answers3

2

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.

Potatoswatter
  • 134,909
  • 25
  • 265
  • 421
1

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);

Soufiane Hassou
  • 17,257
  • 2
  • 39
  • 75
  • I see the answer is the same, i still dont understand what to put where though, please can you copy the whole code that i pasted with the changes or explain more simply – ace Apr 25 '10 at 22:07
  • thanx, however, the function prototype is set, I did not make it and dont think I have access to it? also, I wish to put characters into the function in other places within the code. is there no way to just convert my integer to what is needed? – ace Apr 25 '10 at 22:14
0

Use textprintf_ex like:

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

It works just like printf().

Matthew
  • 47,584
  • 11
  • 86
  • 98