Skip to main content
added 17 characters in body
Source Link
neuro
  • 15.2k
  • 3
  • 38
  • 61

Well, the well known way (before C++11) to do that is using the stream operator :

#include <sstream> std::ostringstream s; int i; s << i; std::string converted(s.str()); 

Of course, you can generalize it for any type using a template function ^^

#include <sstream> template<typename T> std::string toString(const T& value) { std::ostringstream oss; oss << value; return oss.str(); } 

Well the well known way to do that is using the stream operator :

#include <sstream> std::ostringstream s; int i; s << i; std::string converted(s.str()); 

Of course you can generalize it for any type using a template function ^^

#include <sstream> template<typename T> std::string toString(const T& value) { std::ostringstream oss; oss << value; return oss.str(); } 

Well, the well known way (before C++11) to do that is using the stream operator :

#include <sstream> std::ostringstream s; int i; s << i; std::string converted(s.str()); 

Of course, you can generalize it for any type using a template function ^^

#include <sstream> template<typename T> std::string toString(const T& value) { std::ostringstream oss; oss << value; return oss.str(); } 
main not really interesting
Source Link
neuro
  • 15.2k
  • 3
  • 38
  • 61

Well the well known way to do that is using the stream operator :

#include <sstream> int main() { std::ostringstream s;  int i;  s << i;  std::string converted(s.str()); } 

Of course you can generalize it for any type using a template function ^^

#include <sstream> template<typename T> std::string toString(const T& value) { std::ostringstream oss; oss << value; return oss.str(); } 

Well the well known way to do that is using the stream operator :

#include <sstream> int main() { std::ostringstream s;  int i;  s << i;  std::string converted(s.str()); } 

Of course you can generalize it for any type using a template function ^^

#include <sstream> template<typename T> std::string toString(const T& value) { std::ostringstream oss; oss << value; return oss.str(); } 

Well the well known way to do that is using the stream operator :

#include <sstream> std::ostringstream s; int i; s << i; std::string converted(s.str()); 

Of course you can generalize it for any type using a template function ^^

#include <sstream> template<typename T> std::string toString(const T& value) { std::ostringstream oss; oss << value; return oss.str(); } 
Added standard include and compilable example
Source Link
neuro
  • 15.2k
  • 3
  • 38
  • 61

Well the well known way to do that is using the stream operator :

#include <sstream> stringstreamint main() {  std::ostringstream s;  int i;  s << i;  std::string converted(s.str()); } 

Of course you can generalisegeneralize it for any type using a template function ^^

#include <sstream> template<typename T> std::string toString(const T& value) { std::ostringstream oss; oss << value; return oss.str(); } 

Well the well known way to do that is using the stream operator :

#include <sstream> stringstream s; int i; s << i; string converted(s.str()); 

Of course you can generalise it for any type using a template function ^^

#include <sstream> template<typename T> std::string toString(const T& value) { std::ostringstream oss; oss << value; return oss.str(); } 

Well the well known way to do that is using the stream operator :

#include <sstream> int main() {  std::ostringstream s;  int i;  s << i;  std::string converted(s.str()); } 

Of course you can generalize it for any type using a template function ^^

#include <sstream> template<typename T> std::string toString(const T& value) { std::ostringstream oss; oss << value; return oss.str(); } 
Added standard include
Source Link
neuro
  • 15.2k
  • 3
  • 38
  • 61
Loading
Source Link
neuro
  • 15.2k
  • 3
  • 38
  • 61
Loading