Assuming the stream extraction won't fail, will this
if( !(stream >> token) )
throw runtime_error( "Unexpected end of recipe." );
else if( token == "something" )
// do something
else
throw runtime_error( "Unknown token" );
Work like this
if( !(stream >> token) )
throw std::runtime_error( "Unexpected end of recipe." );
if( token == "something" )
// do something
else
throw std::runtime_error( "Unknown token" );
(stream = std::stringstream and token = std::string)
And the expected result being token
contains the next ... token... from the stream?
Is there a better way to handle errors? Like cerr << "error whatever" << endl; exit();
or something, or is my std::runtime_error
good enough?