//: convert.h : Umwandlung von / in string - R.Richter 2010-06-25 ///////////////////////////////////////////////////////////////// #ifndef CONVERT_H #define CONVERT_H #include #include #include #include namespace convert { template std::string str(T const& x) { std::ostringstream os; os << x; return os.str(); } class error : public std::runtime_error { public: error(std::string const& why) : std::runtime_error(why) {} }; template T to(std::string const& s) { std::istringstream is(s); T x; is >> x; if (!is) throw Error("Can't convert \'" + s + "\' to type " + typeid(T).name()); return x; } } // namespace convert #endif // CONVERT_H