Hi
I was just wondering if there was a way to convert a value of double to a string? And if there is what is the command?
Thank You in advance
Hi
I was just wondering if there was a way to convert a value of double to a string? And if there is what is the command?
Thank You in advance
There are several. Do a search on this site and you'll find this question has been asked and answered numerous times.
See the last response in this thread:
http://www.daniweb.com/forums/thread82344.html
Val
#include <sstream>
#include <string>
#include <iostream>
template< typename T > inline std::string to_string( const T& v )
{
std::ostringstream stm ;
return (stm << v) ? stm.str() : "error" ;
}
int main()
{
double value = 1.2345 ;
std::string str_value = to_string(value) ;
// c++0x
// std::string str_value = lexical_cast<std::string>(value) ;
std::cout << value << '\t' << str_value << '\n' ;
}
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.