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 :)

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();


#include <cstdio>

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

Edited 4 Years Ago by Ancient Dragon: n/a

just what I needed...thanks :)

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

This question has already been answered. Start a new discussion instead.