In
if( !( std::cin >> num_bunnies ) || ( std::cin.get(c) && !std::isspace(c) ) )
If
std::cin >> num_bunnies
is successful, (
!( std::cin >> num_bunnies )
is false ), then
1. Extract the very next character in the input buffer into
c with
std::cin.get(c) http://www.cplusplus.com/reference/istream/istream/get/
2. Check if that character is a white space with
std::isspace(c) http://www.cplusplus.com/reference/cctype/isspace/
3. If it is not a white-space character, a whole number was not entered
eg. If the input buffer contained
123.78<newline>
,
123
would be read into
num_bunnies
, and
.
would be read into
c,
.
is not a white-space character.
If the input buffer contained
123xy<newline>
,
123
would be read into
num_bunnies
, and
x
would be read into
c,
x
is not a white-space character.
If the input buffer contained
123<newline>
,
123
would be read into
num_bunnies
, and newline would be read into
c, newline is a white-space character.
If the input buffer contained
123 <newline>
,
123
would be read into
num_bunnies
, and space would be read into
c, space is a white-space character.