0

Bit of a noob question this. I am using a library which has this function: int TextAdd(int x, int y, char *text, int font); I need to use this function to display a score. I have the variable int score and I would like to put it into that function in the style "Score: <variable>" at char *text , but I have no idea how to do this. Please can somebody show me how to convert int to char * and add letters to it?

Thanks :)
Mark

2
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by SgtMe
Featured Replies
  • You have to format that char* before calling TextAdd(). There are several ways to format it, one way is to use std::stringstream from <sstream> header file, another way is to use sprintf(). [code] #include <sstream> int main() { int score = 123; stringstream str; str << score; std::string s; s … Read More

1

You have to format that char* before calling TextAdd(). There are several ways to format it, one way is to use std::stringstream from <sstream> header file, another way is to use sprintf().

#include <sstream>

int main()
{
   int score = 123;
   stringstream str;
   str << score;
   std::string s;
   s = "Score: ";
   s += str.str();
}

or

#include <cstdio>

int main()
{
   int score = 123;
   char text[80];
   sprintf(text,"Score: %d", score);
}

Edited by Ancient Dragon: n/a

Comments
just what I needed...thanks :)
0

Thanks for the reply - I used the sprintf method.
Cheers :)
(solved + rep)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.