Simple question
How would I put an integer or any number into a string, example:
int Time = 10;
char[] String = "Hello dude?";
// My draw text function that takes the pointer to the char string
DrawText( String /* Now how would I add the interget "Time" into the string as a number*/ );
any help is apprecieated.
THX,
JAP
There's a few ways to do it. The two that comes off the top of my head, you can use sstream (stringstreams) or you can use the itoa() function which will turn your int into char * form.
--{You fight like a dairy farmer!}
[edited by - Greatwolf on August 10, 2003 3:00:14 AM]
--{You fight like a dairy farmer!}
[edited by - Greatwolf on August 10, 2003 3:00:14 AM]
A way to do it is using itoa like...
[edited by - FtMonkey on August 10, 2003 3:07:06 AM]
char String[] = "Points: ";int points = 5;char number[20]="";itoa(points,number,10);strcat(String,number);printf("%s\n",String);
[edited by - FtMonkey on August 10, 2003 3:07:06 AM]
In C++:
In C:
[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || MSVC++ Library Fixes || BarrysWorld || E-Mail Me ]
[edited by - Lektrix on August 10, 2003 11:27:02 AM]
#include <sstream>#include <string> ... int time = 10; std::stringstream ss;ss << "Time: " << time;std::string str = ss.str(); DrawText( ..., str.c_str(), ... );
In C:
#include <stdio.h> ... int time = 10; char str[20];sprint( str, "Time: %d", time ); DrawText( ..., str, ... );
[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || MSVC++ Library Fixes || BarrysWorld || E-Mail Me ]
[edited by - Lektrix on August 10, 2003 11:27:02 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement