【发布时间】:2018-02-06 15:26:23
【问题描述】:
在 C++ 中运行代码时,我收到错误 no operator "=" 匹配这些操作数的操作数类型是 std::basic_ostream> = 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;
}
【问题讨论】:
-
cout << average = (num1 + num2) / 2;可能不符合您的要求。检查operator precedence。 -
cin >> num1, num2;也不会像你认为的那样做 -
average = (num1 + num2) / 2; cout << average; -
cout <<在那里做什么?您稍后会显示平均值。 -
Maxim 的答案是正确的,也将
"endl"更改为endl
标签: c++ visual-studio