# convert from integer to string

• 04-02-2006
peter_hii
convert from integer to string
hi, can someone give some idea on how to convert the integer that bring up from the functions and make the integers into one strings..

for example

sqrtOfMonth(month); // this solution is 2
cout<<numPrimeFactor(year)<<endl;// this solution is 2
largestPrimeFactor(year);// this solution is 283
octalDay(day);// this solution is 35
cout<<counter;// this solution is 6

how can i make these single numbers and convert it to one string.
and i want the output to be like 22 28 33 56.. in string..
• 04-02-2006
major_small
you could use stringstreams...
Code:

```#include <iostream>        //for standard I/O #include <sstream>        //for stringstreams #include <string>        //for strings int main() {                std::string line;        //this will hold the output         std::stringstream ss(std::ios::out);        //this will format the output         ss<<2<<2<<283<<35<<6;        //put the integers onto the stream         line=ss.str();                //output the stream into line         ss.str("");                //clear the stream         for(unsigned int i=0;i<line.length();i++)        //loop through each char         {                 if(i%2==0 && i>0)        //for every two                 {                         ss<<' ';        //put a space on the stream                 }                 ss<<line.at(i);                //put the character on the stream         }         line=ss.str();        //save the stream to line                 std::cout<<line<<std::endl;        //output line         return 0; }```
• 04-06-2006
peter_hii
hi, i still need help .. can you help....can we discuss using email...
my email is hiip@optusnet.com.au

waiting for ur email ... so that i can tell you my problem

thank you ..