Vedi se ti funziona:

codice:
template <typename T>
T stot( const std::string &str )
{
	std::istringstream sstream(str);
	T value;
	sstream >> value;
	
	if( sstream.rdstate() & std::stringstream::failbit )
		throw std::ios_base::failure("Unable to convert the string\n");
	
	return value;
}