c++ - 错误 : lvalue required as left operand of assignment, 我收到此错误什么是左值和右值以及如何删除此错误

标签 c++ c linux

我在编译代码时遇到此错误 这是代码

#include <iostream>
using namespace std;
int main()
{
    int l,n,w,h;
    cin>>l>>n;
    while(n--){
        cin>>w>>h;
        if(w>l||h>l)
            cout<<"CROP IT"<<endl;
        if(w==l&&h==l&&w=h)
            cout<<"ACCEPTED"<<endl;
        if(w<l||h<l)
            cout<<"UPLOAD ANOTHER"<<endl;
    }
}

和错误

11:22: error: lvalue required as left operand of assignment

最佳答案

您的if(w==l&&h==l&&w=h)可能是错误的。由于运算符优先级,它正在执行 if((w==l&&h==l&&w)=h)w==l&&h==l&&w部分创造临时值(value)。临时变量始终是右值,并且您不能分配 h到它。

我怀疑你的意思是写if(w==l&&h==l&&w==h) ,但实际上,最后一个w==h有什么意义呢? ?如果两者wh等于l ,那么肯定w等于h .

关于c++ - 错误 : lvalue required as left operand of assignment, 我收到此错误什么是左值和右值以及如何删除此错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38196001/

相关文章:

c++ - 检测运算符 << 序列的结尾

c++ - 为什么从 char* 到 LPCWSTR 的自动转换仅在未设置字符集的情况下有效

c - 在 C 中使用 void* 指针的缺点

linux - ifconfig 设置不维护...?

linux - 将 wget 输出重定向到 perl 脚本输入

linux - 如何使用 bash grep 查找字符串

c++ - ifstream 运算符 >> uint16_t 设置 failbit

c++ - 如何在 C++ 中声明和初始化 2d int vector ?

c - 我从这个 K&R 样本中遗漏了什么?

有人可以解释一下 stdio 缓冲是如何工作的吗?