int to string conversion

Tobias Erbsland drzoom at profzone.ch
Sat Feb 12 12:54:43 GMT 2000


> Jerry L Kreps wrote:
> > Martin Wiebusch wrote:
> > > i was just wondering whether there is a function to convert integer
> > > values to strings in any of the libaries. I already tried itoa, Itoa and
> > > IntToStr. I also noticed there ist an Itoa function defined in the
> > > Integer.h header. But I don't really need an Integer class, just a
> > > little function to convert usual int variables into strings.
> > You can use I/O manipulators (page 259, Practical C++
> > programming)
> Thankx, but I knew that Numbers are converted to strings when you write
> them on stdout with cout << ...
> What I want to do is writing that what in your examples appears on the
> screen to a variable of the type "string".
> Tilo Riemer just wrote me, that I can use "sprintf". But then I have to
> guess how many digits number will have. So it would be great if there
> was something like "sprintf" for instances of the string class. Any
> idea?

Only a hint: Don't use the "strstream" class of the gcc package. You will
get strange errors. But this class should be the solution of your problem:

int x = 23878979;
strstram newnumber;

newnumber << x;

string test = "the new number is: " + newnumber.str();

regards
Tobias





More information about the KDevelop mailing list