1.头文件
#include <iostream>
2.使用说明
让输出流将bool解析成为true或者 false
3、示例代码
#include <iostream>
void test_boolalpha()
{
std::cout << "true is " << true << std::endl;
std::cout << "false is " << false << std::endl;
// 运行下面这个语句, 在输出流中的bool值将发生变化
std::cout << std::boolalpha;
std::cout << "true is " << true << std::endl;
std::cout << "false is " << false << std::endl;
//再次测试,对比差别。
std::cout << "true is " << true << std::endl;
std::cout << "false is " << false << std::endl;
// 运行下面这个语句, 在输出流中的bool值将恢复成0, 1值
std::cout << std::noboolalpha;
std::cout << "true is " << true << std::endl;
std::cout << "false is " << false << std::endl;
}
int main()
{
test_boolalpha();
return 0;
}
输出
true is 1
false is 0
true is true
false is false
true is true
false is false
true is 1
false is 0