How to convert int to string?
How to convert int to string?
I've seen several examples of this, but none that work with the PSP development environment (includes are not there). Does anyone know a sure fire way of doing this? Thanks, for ANY help you can give me.
-
- Posts: 376
- Joined: Wed May 10, 2006 11:31 pm
This isn't really PSP related.
I'm unsure what you mean by converting an int to a string...
Do you mean like so?
Or do you mean so that '1' shows as 'one', '2' as 'two' etc?
The noob bashers are gonna come get you, btw :p
I'm unsure what you mean by converting an int to a string...
Do you mean like so?
Code: Select all
sprintf(char_array, "%d", someint);
The noob bashers are gonna come get you, btw :p
I wrote one that can convert any number type to a string:
I think this will need you to have -lstdc++ added to the libs in your makefile.
Code: Select all
#include <sstream>
#include <string>
#include <iostream>
using namespace std;
template<class T> inline string toString(T number)
{
ostringstream ost;
ost << number;
return ost.str();
}
Of course itoa is not remotely standard so you would expect to find it.
Still nothing comes quite close to this fucktard where he claims sprintf cannot print anything but base 10 numbers and proceeds to present increasingly stupid ways of doing what you just use sprintf for.
http://www.jb.man.ac.uk/~slowe/cpp/itoa.html
Truly unbelievable.
Still nothing comes quite close to this fucktard where he claims sprintf cannot print anything but base 10 numbers and proceeds to present increasingly stupid ways of doing what you just use sprintf for.
http://www.jb.man.ac.uk/~slowe/cpp/itoa.html
Truly unbelievable.