|
Drawing text from variables? |
curious_newbie
Member #11,781
March 2010
|
I understand the basics of allegro 5's draw text routines, but was wondering if it's possible to use text variables when using the routines? example, I'm hoping to do something similar to this: string answer = "blahblah"; al_draw_textf(font18, al_map_rgb(255, 255, 255), WIDTH / 2, HEIGHT / 2, ALLEGRO_ALIGN_CENTRE, "The answer is: %?", answer); Any help is greatly appreciated |
Yodhe23
Member #8,726
June 2007
|
In 'C' I use "strcpy", "strcat", and "itoa" on a char[] (in 'C' a string variable is an array of char) variable, which I pass to the text display function. www.justanotherturn.com |
james_lohr
Member #1,947
February 2002
|
I'm not sure whether or not allegro supports it, but if not then you could wrap al_draw_textf in a function that does by using sprintf (for string formatting), and va_list (for a variable number of arguments to your new function).
|
AMCerasoli
Member #11,955
May 2010
|
Just use answer.c_str() Generates a null-terminated sequence of characters (c-string) with the same content as the string object and returns it as a pointer to an array of characters.
|
curious_newbie
Member #11,781
March 2010
|
The answer.c_str() did exactly what I was looking for, thank you all for the replies |
weapon_S
Member #7,859
October 2006
|
Yodhe23 said: n 'C' I use "strcpy", "strcat", and "itoa" on a char[] itoa is non-standard. For standard, use sprintf (on an extra buffer). |
Yodhe23
Member #8,726
June 2007
|
Thanks for the heads-up about "itoa" and "sprintf", have duly changed my code and coding habits. www.justanotherturn.com |
|