In order to test bool i/o, I tried to run this short program:
#include <iostream>
int main()
{
while(true)
{
bool f;
if (std::cin >> f)
std::cout << f << '\n';
else
{
std::cout << "i/o error\n";
std::cin.clear();
}
}
return 0;
}
Here is the output I get:
g++ -Wall -ansi -pedantic -o boolio boolio.cpp
./boolio
0
0
1
1
2
i/o error
-
i/o error
t
i/o error
i/o error
i/o error
... (infinite loop)
I wonder why I get an infinite loop when I enter 't', and how to prevent it.
Thanks.