number to string
I am having trouble finding how to do this properly.
I know there is a command atoi, but it changes a string to a number.
Im looking for a function(if there exists) to change/cast a number so it can be read as a string
5 = "5"
5.5 = "5.5
also, if there's any c++ reference website you can point me to for stuff such as this, it would be appreciated.(The C one is good, but need with string functions)
How about itoa? ;)
It's not ANSI C though...
well somewhat, although hard for me to find good documentation on it.
Plus, it wouldnt work for a double
you could try sprintf() or stringstreams, both of which are ANSI standard.
trying sprintf() I dont really understand the function
int sprintf(char*, const char*, ...)
although I want to put it into a string, isnt a string just a char pointer? Although I am receiving an error for that.
You need a buffer, where the data will be stored. It have to be an array, not just a pointer.
char* MyName = "Peter Pan";
int MyAge = 28;
//Create the string
sprintf(Buffer, "Hello, my name is %s and I'm %d years old!", MyName, MyAge);
//Print the string
Then you specify a formatting string, and eventually some variables. Pretty much like printf().