How do i print numbers
DuncanShine

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
DuncanShine

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

torhu

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
DuncanShine

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

jmasterx

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

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.

Thread #618054. Printed from Allegro.cc