StringConvert.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00024 #include <cexception.h>
00025 #include <iostream>
00026 #include <sstream>
00027 #include <string>
00028
00029 template <class t> t convertString( const std::string& str) {
00030 std::istringstream s(str);
00031 t buf;
00032 if (!(s >> buf)) {
00033 throw( cException("convertString: parsing of string %s failed", str.c_str()) );
00034 }
00035 return buf;
00036 }
00037
00038 template <class t> std::string convertToString( const t& val) {
00039 std::ostringstream s;
00040 if (!(s << val)) {
00041 throw( cException("convertToString: cannot convert value to string") );
00042 }
00043 return s.str();
00044 }
00045