为什么我会收到此错误:类型为'int'和'<unresolved overloaded =“”function =“”type =“”>'to binary'operator&lt;&lt;'的无效操作数

时间:2015-07-03 03:54:21

标签: c++

我是初学者的定义。我在学校的Linux服务器上使用C ++。我一直在这个项目工作几个小时,我无法弄清楚我做错了什么。我已经重新分配变量并重新调整我的公式,但没有任何作用。请帮忙。

#include<iostream>
#include<string>
using namespace std;

const int f=5;

int main ()
{
        int a,b,c,d,e,sum,avg;
        cout << "Please enter five numbers. " << endl;
        cin >> a >> b >> c >> d >> e;
        sum= a+b+c+d+e;
        cout << "The average of those numbers is: " << endl;
        cout << avg =(sum / f) << endl ;
return 0;
}

错误说明:类型'int'和''到二进制'运算符的无效操作数&lt;&lt;'&lt;'

1 个答案:

答案 0 :(得分:5)

基本上问题是如何解析cout << avg =(sum / f) << endl

<<是左关联的,其优先级高于=,因此表达式被解析为

(cout << avg) = ((sum/f) << endl)

现在,作业的右侧是int << endl会引发错误,因为操作没有意义(<<没有为int, decltype(endl)参数定义<\ n} < / p>

相关问题