quote:Original post by Empirical
Oh right, well, im sure it will be ok! Thanks all for your help.
Trust us. It won't be alright.
Instead have a non-member function so that you can convert from a string to whatever you want:
//convert string to type Ttemplate<class T>T to(std::string& str) { T result; std::stringstream ss; ss << str; ss >> result; return result;}int i = to<int>("10");float f = to<float>("11.5f");double d = to<double>("3.142");complex<double> c = to<complex<double> >("(3.2, 7.5)");
These functions have already been written for you in
boost.
lexical_cast. read up on it
[edited by - petewood on March 22, 2004 6:23:03 PM]