What compiler had you used? I get the same behavior with Visual Studio 2008. I would have thought that the integral value should get implicitly converted to a boolean. In fact when I debugged the code in VC++, I do see that it is able to get the value of the user input (say 8) but then there is a certain check which then fails and results in setting of the failbit of the stream. If you check the status of the cin stream post that read, you should see the failbit set which means the read had failed.
VC++ code (file: xlocnum, function: do_get)
The check _Ulo <= 1 is what fails. _Ulo is an unsigned long which does get successfully evaluated to 8 (the input). So, it is basically only allowing inputs as 0 and 1 via the stream.Code:{ // get zero or nonzero integer
char _Ac[_MAX_INT_DIG], *_Ep;
int _Errno = 0;
const unsigned long _Ulo = ::_Stoulx(_Ac, &_Ep,
_Getifld(_Ac, _First, _Last, _Iosbase.flags(),
_Iosbase.getloc()), &_Errno);
if (_Ep != _Ac && _Errno == 0 && _Ulo <= 1)
_Ans = _Ulo;
}
As has been written above, it is incorrect to say that a bool can only be assigned a value "true" or "false". Whatever value you try to assign, for example, an integral value say != 0, that value should get converted to a boolean and then that value set up as the value of the bool. So, it should be perfectly legal to do that.
Could this be a bug in VC++? I am not sure but I would have thought that it would have considered any non-zero value as true. Because, if I just simply set the value of boolean as 8 instead of reading from the stream, the automatic conversion rules kick in and the code works as expected. I don't have any other compiler but can anyone check what behavior is there with g++ or any other compiler?

