爲什麼布爾型&&
在這種情況下工作?當我輸入「黃色」不應該「短路」,而不檢查第二個條件,因爲第一個條件「紅色」是錯誤的?爲什麼我在工作的時候不應該這樣做?
#include <iostream>
#include <string>
using namespace std;
int main()
{
string color;
do
{
cout << "Pick one of the colors: red, yellow, or blue\n";
cin >> color;
}while ((color != "red") && (color != "yellow") && (color != "blue"));
{
cout << "I like that color too";
return 0;
}
}
爲什麼你會使用第二對括號呢?這是問題的一部分? – Emadpres
您只需在整個條件之前使用一個小「!」來糾正它。 – Emadpres
'_因爲第一個條件「紅色」是假的?_'實際上不是。這可能是整個混亂的根源。 – ComicSansMS