You can use these functions to convert to and from:
template <class T> bool convertFromStr(string &str, T *var) { istringstream ss(str); return (ss >> *var); } template <class T> string convertToStr(T *var) { ostringstream ss; ss << *var; return ss.str(); }
Example:
double d = 1.234567; string str = convertToStr<double>(&d); cout << str << endl; double d2; convertFromStr<double>(str, &d2); cout << d2 << endl;
Morten kristensen
source share