cout << string_cast<int>("12345") << endl; string转double的用法: cout << string_cast<double>("12345.78") << endl;
1template <typename T>2classstring_cast3{4public:5string_cast(conststd::string&from): m_from(from) {6}7operatorT()const{8std::stringstream sstr(m_from);9T ret;10try{11sstr >>ret;12}13catch(std::exception &e)14{15returnT(0);16}17returnret;18}19private:20conststd::string&m_fro...