I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
Index » Programming » Tutorials » C & C++ » Basic »

Converting a number to a std::string

john\′s Photo
5 Dec 07, 6:50AM
(1 reply)
Converting a number to a std::string
There are no obvious functions in pure C++ (lots in C!) to convert a number into an std::string. The way to do this is by using a stringstream, i.e.

#include<iostream>
 
#include<sstream>
std::string NumToString(double num)
{
  std::stringstream s;
  s << num;
  return s.str();
}
 
int main()
{
  double anum=3.141592;
  std::string str = NumToString(anum);
 
  std::cout << "Here is our string: "<< str << std::endl;
}
jamess86607\′s Photo
19 Sep 13, 1:42PM
hello everyone welcome to this forum.Here u find all your questions and get your answers. right now i am unable to find your answer.If you want to see c programming you can go through this. --------- [url=http://www.javatutorials.tk] C Programming [/url]
Currently you need to be logged in to leave a message.