C ++中的布尔流输出表示 [英] Boolean stream output representation in C++
本文介绍了C ++中的布尔流输出表示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有c ++代码
int main()
{
int a = 5, b=5;
bool c;
c = a == b;
cout << c << endl;
return 0;
}
输出为1
任何人都请解释一下输出如何为1以及为什么它不是真实的?
anyone please explain me how come output is 1 and why it is not true?
推荐答案
因为默认情况下,这就是 std :: ostream :: operator<<
格式化 bool
值的方式.它为 true
输出 1
,为 false
输出 0
.如果要打印文本"true"
或"false"
,可以使用 boolalpha
io机械手:
Because that's how std::ostream::operator<<
formats bool
values by default. It outputs a 1
for true
, and a 0
for false
. If you want to print the text "true"
or "false"
, you can use the boolalpha
io manipulator:
std::cout << std::boolalpha << c;
这篇关于C ++中的布尔流输出表示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文