以下程序的输出结果是“they are not equal”,但我期望的结果是“they are equal”,因为三个比较的变量(
x
,y
和z
)是相等的。为什么会这样呢?#include <iostream>
int main()
{
int y, x, z;
y = 3;
x = 3;
z = 3;
if (x == y == z)
{
std::cout << "they are equal\n";
}
else
{
std::cout << "they are not equal\n";
}
}
if (x == y == z)
不会做你想要的事情。 - drescherjm