在输出逻辑表达式的值时,需注意运算优先级的问题:
示例:
正确代码:
#include <iostream>
using namespace std;
int main()
{int a = 1;int b = 2;cout << (a==b) << endl;return 0;
}
输出结果为 0
错误代码:
#include <iostream>
using namespace std;
int main()
{int a = 1;int b = 2;cout << a==b << endl;return 0;
}
cout <<的那一行代码报错:
[Error] invalid operands of types ‘int’ and ‘’ to binary ‘operator<<’
注:本样例中的==只是示例,实际上还可以是+=,-=,&&,||等.
本文发布于:2024-02-03 07:24:55,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170691629349516.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |