I'm using the iomanip header and boolalpha to print the words "true" and "false". I have a program that demonstrates a simple use of boolean variables. It goes like this:
Code:
#include <iomanip>
#include <conio.h>
using namespace std;
int main()
{
bool b;
b = false;
cout << "b is " << b << endl;
cout << "In other words, b is " << boolalpha << b << endl << endl;
b = true;
cout << "b is " << b << endl;
cout << "In other words, b is " << boolalpha << b << endl << endl;
if(b)
cout << "Karen has a boatload of problems, but she's not all bad." << endl;
b = false;
if(b)
cout << "Jerry is a nice guy...but actually that's a lie" << endl;
cout << "13 > 11 is " << (13 > 11);
getch();
return 0;
}
When I run it the first two cout statements look fine:
b is 0
In other words, b is false
No problem there but when I run the next two cout statements I see this:
b is true
In other words, b is true
So I'm wondering why the compiler is not printing "b is 1" before I specifically instruct it to print "b is true" in the following statement?
I'm guessing that when I use boolalpha for the first time in the cout statement, that is setting it for the rest of the program? Do I need to shut it off before I use it again?