. Advertisement .
..3..
. Advertisement .
..4..
Recently, I ran some of my p code, and it gave the warning text:
Invalid operands to binary expression.
While searching, I realized that some people added some command lines in my sample above. But I don’t think it is the best way to correct the problem – invalid operands to binary expression c++. How would you explain this trouble? or Is there a better way? Below is the detail of the command that I used:
#include <iostream>
using namespace std;
int main()
{
int thisisanumber();
cout << "Please enter a number: ";
cin >> thisisanumber;
cin.ignore();
cout << "You entered"<< thisisanumber <<"\n";
cin.get();
}
The cause: This error occurs because the most vexing has made you a victim. This means that
thisisanumber
is being considered a function.Solution: You should be able to remove the parentheses.
You might also consider making it more readable like
thisIsANumber
.thisIsANumber
uses the in-case naming convention if you need it.Use brackets to declare your variable, like
It is read as a function by brackets. A function cannot be passed to
>>
as a parameter.