Bis*_*ist 1 c++ compiler-errors operator-precedence
我可以做这个 int c= 0xF^0xF; cout << c;
但是cout << 0xF^0xF;不会编译.为什么?
根据C++ Operator Precedence,operator<<具有更高的优先级operator^,因此cout << 0xF^0xF;等效于:
(cout << 0xF) ^ 0xF;
Run Code Online (Sandbox Code Playgroud)
cout << 0xF返回cout(即a std::ostream),不能用作操作数operator^.
您可以添加括号以指定正确的优先级:
cout << (0xF ^ 0xF);
Run Code Online (Sandbox Code Playgroud)