C++ stringify

30 Aug 2008

Quick stringify hack, turn anything (printable) into a string.

#include <sstream>
#include <string>

template<typename T>
inline std::string stringify(const T& x) {
  std::ostringstream o;
  o << x;
  return o.str();
}

Discussion and a more robust version at the C++ FAQ Lite.