const char * nums( "123");
std::stringstream ss( std::string( nums ) ); // simpler way
ss >> i >> garbage;
if ( !garbage.empty() )
You can also use boost::lexical_cast which does pretty much that above, and throws a bad_cast exception, though personally I prefer to throw my own exception with a description of what you were trying to cast to what.