-
Numeric to string help
how would i go about assigning a numerical data type to a string/composite string, i am havig the following problem:
i want to pass the following to the DrawCaption Api:
int Score=1234;
DrawCaption(...,"Your Score: " + Score ,...);
but you have to pass a purely string varialbe so i tried this:
int Score=1234;
char ScoreText[] = "Your Score: ";
ScoreText[8] = Score; //and i know this just passes the number to ascii character form
DrawCaption(...,ScoreText,...);
so as u can see no good, do i have to create my own class to do this or is there a pre built class for this, or am i just not using the correct syntax???
any help would be great
-
Use a string stream object.
Code:
#include <strstream>
#include <iostream>
#include <string>
using std::string;
using std::strstream;
using std::cout;
using std::endl;
using std::ends;
int main()
{
string FinalString;
int Score = 1234;
strstream TempString;
TempString << "Your Score: " << Score << ends;
FinalString = TempString.str();
cout << FinalString << endl;
return 0;
}
I think that should be correct and give you a sample of what to do. Should output "Your Score: 1234"
-
Thats great thanks for the help