Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » How do i print numbers

This thread is locked; no one can reply to it. rss feed Print
How do i print numbers
DuncanShine
Member #17,479
March 2020

I'm trying to use al_draw_text but it wont work with numbers and i'm not sure how to convert to const char*

torhu
Member #2,727
September 2002
avatar

DuncanShine
Member #17,479
March 2020

that didnt make a difference it's still asking for a const char

torhu
Member #2,727
September 2002
avatar

The const char pointer is the format string, the values are added as extra arguments after that. Look at the examples here:
https://www.cplusplus.com/reference/cstdio/printf/

jmasterx
Member #11,410
October 2009

DuncanShine
Member #17,479
March 2020

but what does stringstream actually do? it doesnt seem to convert to const char*

jmasterx
Member #11,410
October 2009

It works just like std cout
https://github.com/jmasterx/Agui/blob/master/demo/AguiCalc/AguiCalc/Calculator.cpp#L292

it will output a std string which you can do .c_str() to get a const char*

you can << whaterver you want.

Like

std::stringstream ss;

ss << "I ate" << 22 << "Hot Dogs";
al_draw_text(ss.str().c_str());

torhu
Member #2,727
September 2002
avatar

Drawing an int would look like this:

al_draw_textf(my_font, my_color, x_pos, y_pos, 0, "Here it is: %d", my_value);

Or replace %d with %f to draw a float or double, etc.

Go to: