
-----------------------------------
AsianSensation
Thu Feb 24, 2005 7:17 pm

Integer to string conversion?
-----------------------------------
What is an easy way to convert from a integer to a string object (not an array of characters)?

-----------------------------------
wtd
Thu Feb 24, 2005 7:43 pm


-----------------------------------
Use a stringstream.

#include 
#include 

int main()
{
   int foo = 42;
   std::string bar;
   std::stringstream baz;

   baz > bar;

   return 0;
}

-----------------------------------
AsianSensation
Thu Feb 24, 2005 7:51 pm


-----------------------------------
Wow, cool, I read your other tutorial on conversion using stringstream, I thought it was just extracting numbers from strings only, didn't know it could work the other way too. Way cool. Thanks alot.

-----------------------------------
cimnik029
Wed Mar 30, 2005 8:19 pm


-----------------------------------
or you could do it like this, if you want to deal with std::strings.

#include 
#include 

int main()
{
   int foo = 42;
   std::string bar;
   std::stringstream baz;

   baz 