Both std::cin and std::cout provide a conversion to a void* type, but not to a boolean:
operator void* (); // zero if and only if fail()
What use does a conversion to a boolean have, and which pitfalls does the current implementation save us from?
First off, a conversion to a boolean type is useful for the following construct:
while (cin >> str) // ...
But why is it a conversion to a void* and not to a bool?
This is actually pretty clever. If there was a conversion to a bool type, the following lines would not generate a compile error:
int n = 3; cin << n; // convert cin to bool, promote to int & shiftleft cout >> n; // convert cout to bool, promote to int & shiftright
This is a pretty good example of a smart design by the STL folks.