我收到错误没有运算符“=”匹配这些操作数操作数类型是std :: basic_ostream>在C ++中运行代码时是int,我不确定是什么导致错误。
#include <iostream>
#include <string>
#include <fstream>
#include <cctype>
using namespace std;
int main()
{
int num1, num2;
double average;
// Input 2 integers
cout << "Enter two integers separated by one or more spaces: ";
cin >> num1, num2;
//Find and display their average
cout << average = (num1 + num2) / 2;
cout << "\nThe average of these 2 numbers is " << average << "endl";
return 0;
}
答案 0 :(得分:1)
编译器处理
cout << average = (num1 + num2) / 2;
如:
(cout << average) = ((num1 + num2) / 2);
有关详细信息,请参阅C++ operator precedence。
修正:
cout << (average = (num1 + num2) / 2);
更喜欢简单的陈述:
average = (num1 + num2) / 2;
cout << average;
另外
cin >> num1, num2;
应该是
cin >> num1 >> num2;