Integers to strings.

Started by
11 comments, last by GekkoCube 22 years, 3 months ago
quote:Original post by GekkoCube
this method seems easier than all the previously posted stuff.

Doesn''t beat stringstream.
quote:Or am i missing something?

stringstream (I''m starting to feel like that AFLAK duck...). Follow the links I posted, especially the DevX one; it gives a number of really good examples.

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!
Advertisement
quote:Original post by max621
sprintf(Array, "%c %d", sex, age);

An excellent example why stringstream is superior: you don''t have to remember/lookup no fecking format specifiers!
int age = 120;char sex = ''M'';string str;stringstream sstrm;sstrm << "Age: " << age << " Sex: " << sex;sstrm >> str;cout << str << endl; 

You could also have done ''cout << sstr.str() << endl;'' or so.

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!

Hey thanks everyone!

I remember using sprintf...I just havent used it in such a long time. Thanks Minion, thats exactly what I''ve been looking for, sprintf()!

Also thanks for the stringstream tip. That does seem to beat the sprintf(), although im more comfortable with it.

so special thanks to Minion and the AFLAK guy.


~ I''''m a wannabe programmer ~

This topic is closed to new replies.

Advertisement