需要左值作为赋值错误的左操作数通过 if 语句
lvalue required as left operand of assignment error via if statement
我看过类似的问题,但作为一个完全的新手,它们并没有多大帮助,当我尝试运行我的最终 if 语句时,我遇到了这个错误,我怎样才能让我的 cout 语句更清晰?它的预期目的是输出它可以接受多少袋垃圾,用户试图给它多少袋,以及如果它不能全部拿走,将剩下多少袋子。
while(( reg < 50) && (met< 20) && (glass < 20))
{
reg=reg+reg; met=met+met; glass=glass+glass;
cout<< " I have enough "<< endl;
if(reg+=reg > 50){
cout<< "I can only accept " << 50 - (reg+=reg) << "of your " << (reg+=reg)<<" regular bags of garbage, I'll leave the other " << 50 - (reg+= reg)<< " I'll leave the other " << reg- (50 - reg+=reg)<< endl;
}
50 - reg += reg;
operator+=
的优先级低于operator-
。上述声明被解释为:
(50 - reg) += reg;
这行不通。您可能想要:
50 - (reg += reg);
相关文章:
- 我的简单if-else语句是如何无法访问的代码
- 如何将enable-if与模板参数和参数包一起使用
- 无论条件是否为true,if总是在c++中执行
- Arduino:for/while/if在void setup()或void loop()之前?——错误:之前需要不合格
- 控制允许动态运行c++的并发操作数
- Insert函数不适用于2 if语句C++
- If语句未被求值C++
- C++嵌套if语句,基本货币交换
- 多个If语句与使用逻辑运算符计算条件的单个语句的比较
- 是否可以使用if constexpr删除控制流语句
- 要与"if constexpr"一起使用的编译时消息(在预处理器之后)
- 如何删除peer if else分支中的冗长句子
- 为什么C++逐位AND运算符在不同大小的操作数中表现为这样
- 我似乎对if/else的基本语句有问题:/
- if数组上的随机数
- 将按位if条件转换为普通if条件
- If语句在c++中被忽略
- C++ 带有向量的 IF 计算操作数
- 需要左值作为赋值错误的左操作数通过 if 语句
- C/C++ 中的 'if' 语句是否将操作数转换为整数?