我能做到int c= 0xF^0xF; cout << c;
但是cout << 0xF^0xF;
不会编译。为什么?
最佳答案
根据C++ Operator Precedence , operator<<
优先级高于 operator^
,所以cout << 0xF^0xF;
相当于:
(cout << 0xF) ^ 0xF;
cout << 0xF
返回cout
(即 std::ostream
),不能用作 operator^
的操作数.
您可以添加括号来指定正确的优先级:
cout << (0xF ^ 0xF);
关于c++ - 使用cout输出按位运算符结果时编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41234327/