表达式必须为L值

Expression must be an L value

本文关键字:表达式      更新时间:2023-10-16

我正在尝试制作一个可以识别直角三角形的公式。我有一些问题与"a"和=号。

错误1:'=';左操作数必须为左值
错误2:"a"。表达式必须是一个可修改的左值。

帮忙吗?

#include "stdafx.h"
#include <iostream>
#include <cstdio>
#include <cmath>
 using namespace std; 

int main()
{
    int a; 
    int b;
    int c;
    cout << "Input value for A." << endl; 
    cin >> a; 
    cout << "Input value for B. " << endl; 
    cin >> b; 
    cout << "Input value for C. " << endl; 
    cin >> c; 
    a ^ 2 + b ^ 2 = c ^ 2; 
    return 0;
}

^运算符在c++中用于获得逐位异或。你应该这样做:

代替a ^ 2 + b ^ 2 = c ^ 2语句,写一个这样的块:

    if(pow(c, 2) == pow(a, 2) + pow(b, 2))
        std :: cout << "true";
    else
        std :: cout << "false";