gpt4 book ai didi

c++ - io流错误

转载 作者:太空狗 更新时间:2023-10-29 23:34:35 25 4
gpt4 key购买 nike

代码中最后两条语句有什么问题?

#include <iostream>
using namespace std;
int main()
{
cout << "2 + 4 = " << 2 + 4 << endl;
cout << "2 * 4 = " << 2 * 4 << endl;
cout << "2 | 4 = " << 2 | 4 << endl;
cout << "2 & 4 = " << 2 & 4 << endl;

我应该怎么做才能解决这个问题?

最佳答案

What is the problem with the last two statements in the code?

运算符优先级。 |&优先级低于 << , 所以 cout << "2 & 4 = " << 2 & 4 << endl;被解析为 (cout << "2 & 4 = " << 2) & (4 << endl;) .

What should I do to fix this?

将括号放在 2 | 4 周围和 2 & 4 .

关于c++ - io流错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2617455/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com