我是初学者的定义。我在学校的 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’ 和 “ 类型的无效操作数到二进制 ‘operator<<’
原文由 Bigrednerd82 发布,翻译遵循 CC BY-SA 4.0 许可协议
基本上问题是如何解析
cout << avg =(sum / f) << endl
。<<
是左关联的并且优先级高于 = 所以表达式被解析为现在,您的作业右侧是
int << endl
这会引发错误,因为该操作没有意义(<<
它没有为int, decltype(endl)
参数定义)