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

时间:2011-12-28 00:00:58

标签: c++ xcode macos

其他人已经回答了这个问题,但我无法弄清楚如何将其应用到我的代码中,因为坦白说,这太简单了。

#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;
}

2 个答案:

答案 0 :(得分:6)

您想设置c,因此必须

c = a+b;

a+b是一个表达式,而不是您可以指定的变量。

答案 1 :(得分:0)

左侧是a+b,它不是可赋值变量(左值)。