Simple question

Started by
3 comments, last by JIMbond21 20 years, 8 months ago
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
THX,JAP
Advertisement
Check the MSDN for printf or sprintf or whatever the function is called.
____________________________________________________________AAAAA: American Association Against Adobe AcrobatYou know you hate PDFs...
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!}

A way to do it is using itoa like...

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]
The monkeys are listening...
In C++:
#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]
[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || CUJ || MSVC++ Library Fixes || BarrysWorld || [email=lektrix@barrysworld.com]E-Mail Me[/email] ]

This topic is closed to new replies.

Advertisement