因此,我目前正在学习如何使用C ++进行编码。我在下面遇到了以下代码。
// =======================
// Lesson 2.4.3 - Do while
// =======================
#include<iostream>
using namespace std;
int main()
{
bool condition = false;
do
{
cout << "Enter a 0 to quit or 1 to continue: ";
cin >> condition;
}
while (condition);
}
为什么C ++自动知道0中断循环而1继续循环?它是否与知道0 = false且以上所有内容为true的命令有关?
感谢那些能提供帮助的人。
最佳答案
变量condition
的类型为bool
,因此其值可以为true
或false
。如果为假,则循环终止。在bool
的输入和输出中,0为false,1为true。
关于c++ - 对以下代码感到困惑,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20622311/