我在编译代码时遇到此错误 这是代码
#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
有什么意义呢? ?如果两者w
和h
等于l
,那么肯定w
等于h
.
关于c++ - 错误 : lvalue required as left operand of assignment, 我收到此错误什么是左值和右值以及如何删除此错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38196001/