Skip to main content
4 of 5
main not really interesting
neuro
  • 15.2k
  • 3
  • 38
  • 61

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(); } 
neuro
  • 15.2k
  • 3
  • 38
  • 61