boolalpha 和 noboolalpha - 关键字

it2022-05-05  157

转自:http://blog.csdn.net/huang_xw/article/details/8196885

1.头文件#include <ios>

2. 功能

使bool型变量按照false、true的格式输出。如不使用该标识符,那么结果会按照1、0的格式输出

 

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; // 运行下面这个语句, 在输出流中的bool值将恢复成0, 1值 std::cout << std::noboolalpha; std::cout << "true is " << true << std::endl; std::cout << "false is " << false << std::endl; /* 输出如下: true is 1 false is 0 true is true false is false true is 1 false is 0 */ }

转载于:https://www.cnblogs.com/claremore/p/4712155.html


最新回复(0)