赋值错误的左操作数需要左值

Lvalue required as left operand of asignment error

本文关键字:操作数 赋值 错误      更新时间:2023-10-16

这个问题已经被其他人回答过了,但是我不知道如何将它应用到我的代码中,因为,坦率地说,它太简单了。

#include <iostream>
#include <string>
using namespace std;
int pythagorean () 
    int a;
    int b;
    int c;
    cout << "A: ";
    cin >> a;
    cout << "B; ";
    cin >> b;
    a*=a;
    b*=b;
    a+b=c; //This is where I get the error. Any ideas?
    cout << c;
    return 0;
}

你想设置c,所以它必须是

c = a+b;

a+b是一个表达式,不是一个可以赋值的变量。

左边是a+b,它不是一个可赋值的变量(lvalue)