How to convert int to string?

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Crux
Posts: 10
Joined: Sun May 25, 2008 1:46 pm

How to convert int to string?

Post by Crux »

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.
Insert_witty_name
Posts: 376
Joined: Wed May 10, 2006 11:31 pm

Post by Insert_witty_name »

This isn't really PSP related.

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);
Or do you mean so that '1' shows as 'one', '2' as 'two' etc?

The noob bashers are gonna come get you, btw :p
Crux
Posts: 10
Joined: Sun May 25, 2008 1:46 pm

Post by Crux »

Lol thats fine I can hear them coming. But like I believe you've said to many before, we all start somewhere. I do try to contribute back to the forum, but my expertise is VERY limited, but I hope to one day offer as much back as many as you do.

With that said I'll go attempt the code thank-you!
daaa57150
Posts: 28
Joined: Fri Nov 17, 2006 10:35 pm

Post by daaa57150 »

I wrote one that can convert any number type to a string:

Code: Select all

#include <sstream>
#include <string>
#include <iostream>

using namespace std;

template<class T> inline string toString&#40;T number&#41;
&#123;
	ostringstream ost;
	ost << number;
	return ost.str&#40;&#41;;
&#125;
I think this will need you to have -lstdc++ added to the libs in your makefile.
whistler
Posts: 39
Joined: Tue Mar 04, 2008 7:08 am

Post by whistler »

google itoa (integer to ascii)

edit nvm i've grepped the headers and it looks like this function may not be supported
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

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.
Post Reply