Generic STL Type Conversion

January 10, 2005

This does a nifty job of converting to and from all the base types and more.

#include <sstream>
#include <string>
 
template <class out_type, class in_value>
out_type convert(const in_value& t)
{
	std::stringstream stream;
 	stream << t;
 	out_type result;
 	stream >> result;
 	return result;
}

Related Posts