isdigit() and isspace() return zero if the input is not a digit or space, respectively, or non-zero otherwise (they return int). Note that for the purposes of bool-to-int conversion, true is 1 and false is 0. However, the C++ standard says that the boolean true condition is equal to !false,
whereas false == 0. Hence, any non-zero value is true.
When you are testing == true, you are testing against 1 (due to above bool-to-int conversion). However, as the function documentation says, it returns
non-zero is the condition is true.
In other words, the correct way to write the line is:
and
As a general rule, you should never compare against true like this:
|
if( someCondition == true )
|
due to the bool-to-int conversion rule. It is always better to write
Because false is zero and zero is false, it is ok to write
|
if( someCondition == false )
|
however I have always preferred