![]() |
|
Drawing string from a variable to the screen? |
j0rdant13
Member #14,974
March 2013
|
Pretty much what the title says al_draw_textf(myFont, al_map_rgb(255,255,255), 0, 260, 0, "Player walking: %std::string", walkString); |
Arvidsson
Member #4,603
May 2004
![]() |
Assuming walkString is a std::string, my guess would be: al_draw_textf(myFont, al_map_rgb(255,255,255), 0, 260, 0, "Player walking: %s", walkString.c_str());
|
j0rdant13
Member #14,974
March 2013
|
wow its that simple haha thankyou! Btw what does the c_str() mean? |
pkrcel
Member #14,001
February 2012
|
That's correct, maybe for future reference keep a tab on the various printf function format specifiers (another link). EDIT: It is unlikely that Google shares your distaste for capitalism. - Derezo |
j0rdant13
Member #14,974
March 2013
|
thanks, bookmarked that link, last question, is it bad using this? |
LennyLen
Member #5,313
December 2004
![]() |
j0rdant13 said: thanks, bookmarked that link, last question, is it bad using this? No. It's the best way to use C++ strings with C libraries.
|
Neil Walker
Member #210
April 2000
![]() |
c_str converts a string into a char*, i.e. to something you can use in C. A typical reason for doing this is to format strings using a stringstream, e.g. ostringstream os; os << "Player walking: " << walkString << " their score is " << 25; string s1=os.str(); al_draw_textf(myFont, al_map_rgb(255,255,255), 0, 260, 0, s1.c_str());
Or words to that effect, I'm typing not compiling Neil. wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie |
j0rdant13
Member #14,974
March 2013
|
Wow thanks for the replies, problem solved and understood |
|