Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Integer blitting (text output)

This thread is locked; no one can reply to it. rss feed Print
Integer blitting (text output)
GuitarGod1134
Member #8,482
April 2007

im trying to output the players health and mana for my game but according to the error in deccpp
invalid conversion from 'int' to const char*
textout_ex( buffer, font, text, x, y, color, color);
does not work with integers. so how do i print integers to the screen?

Dustin Dettmer
Member #3,935
October 2003
avatar

#include <sstream>
using namespace std;

...

stringstream ss;
ss << 49;

textout_ex(buffer, font, ss.str().c_str(), x, y, color, color);

Or (because I know someone else is going to post this :P):

textprintf_ex(buffer, font, x, y, color, color, "%d", 49);

On a side note: Using the same color for fg and bg is probably not what you want. I'd recommend -1 for your bg parameter.

GuitarGod1134
Member #8,482
April 2007

I dont really understand the second function you did. I get the first 6 parameters but what are the last two? The int and ....?

CGamesPlay
Member #2,559
July 2002
avatar

Read about the printf function:
printf

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Dustin Dettmer
Member #3,935
October 2003
avatar

Just stick with the first solution, its better anyway.

LennyLen
Member #5,313
December 2004
avatar

You should probably read (or re-read) some tutorials on C/C++ basics as well.

Archon
Member #4,195
January 2004
avatar

Quote:

Just stick with the first solution, its better anyway.

I'd go with the second method for consistency.

Quote:

I dont really understand the second function you did. I get the first 6 parameters but what are the last two? The int and ....?

text_printf is Allegro's version of the standard printf function with extra parameters (destination bitmap, colour, position).

GuitarGod1134
Member #8,482
April 2007

Ok I read it. thx;D

Go to: