Use cout to print out bool values as true and false?

Have you tried printing out bool using cout.

Well who hasn’t, and most of you might have got results like 0/1. For eg:

[sourcecode language=’cpp’]cout < < "1 > 2: ” < <  ( 1 > 2 );[/sourcecode]

Output
1 > 2: 0
Well how to print out true or false directly instead of 0 and 1. Use boolalpha manipulator…

[sourcecode language=’cpp’]cout < < "1 > 2: ” < <  boolalpha <<  bool( 1 > 2 );[/sourcecode]

Output
1 > 2: false

To unset boolalpha effect on cout use noboolalpha likewise…

[sourcecode language=’cpp’]cout << noboolalpha[/sourcecode]

Appreciate your comments...