Given the following code;
#include<iostream>
using namespace std;
int main(){
int number_1 = 3;
int result_1 = 10;
result_1 += number_1;
cout << ++result_1;
cout << result_1 += number_1;
}
The line cout << result_1 += number_1;
giving me an error.
no match for 'operator+=' (operand types are 'std::basic_ostream' and 'int')
On the other hand, the cout << ++result_1;
is running without any problems.
Can anyone please explain what is the error is for, what the cause is?
cout << result_1
returns thecout
object. That object doesn't have a+=
overload for ints. – Hatted Rooster