使用COUT来输出位运算符的结果时编译错误
Compile error when using cout to output result of bitwise operator
我可以做这个 int c= 0xF^0xF; cout << c;
但是cout << 0xF^0xF;
不会编译。为什么?
根据C 操作员优先级,operator<<
的优先级高于operator^
,因此cout << 0xF^0xF;
等于:
(cout << 0xF) ^ 0xF;
cout << 0xF
返回cout
(即std::ostream
),它不能用作operator^
的操作数。
您可以添加括号以指定正确的优先级:
cout << (0xF ^ 0xF);
相关文章:
- 在没有定义返回类型的函数中返回布尔值,并将结果保存在无错误的char编译中-为什么
- C++编译器能在编译时计算出文字的除法结果吗
- wcslen() 在使用编译指示包时返回不正确的结果
- 未经GCC优化而编译的简单C++程序不会产生预期的结果
- 重用编译器前端的结果,以加快多个配置/平台的C++代码编译
- 为什么 gcc 和 clang 为我的程序编译为不同的"const"结果?
- 用不同版本的Ubuntu上的GCC编译会产生不同的结果
- 在编译时拆分字符串在不同的编译器上会得到不同的结果
- 使用不同版本编译的相同代码提供不同的结果
- std::cout会影响编译的结果吗
- 传递右值引用结果编译错误unique_ptr
- 编译时检查大小是否为..(args) 匹配来自 constexpr 函数的结果
- GCC:为什么编译.HPP文件与.cpp文件的结果不同
- 代码检查 std::unordered_set::find 的结果无法编译
- 使用COUT来输出位运算符的结果时编译错误
- g++ 对象文件参数位置很重要,并给出无法正常编译的不同结果
- gluPerspective with SFML:相同的编译,不同的结果.图形未显示
- 如何在C++中打印编译时计算的结果
- 编译一个相当简单的c++11程序时,gcc和clang之间的结果不同
- Boost bjam:将结果与预编译库链接