incalid oprands to binary expression
时间: 2024-05-15 17:16:42 浏览: 47
"Invalid operands to binary expression" is an error message that occurs when the operands (values or variables) used in a binary expression (an operation with two operands such as addition, subtraction, multiplication, or division) are not compatible with each other.
For example, trying to add a string and an integer or dividing by zero would result in this error message.
Here are some examples of invalid operands to binary expression:
1. Adding a string and an integer:
```
string str = "hello";
int num = 5;
cout << str + num; // error: invalid operands to binary expression ('std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >' and 'int')
```
2. Dividing by zero:
```
int num1 = 10;
int num2 = 0;
cout << num1 / num2; // error: invalid operands to binary expression ('int' and 'int')
```
3. Using bitwise operators on non-integer types:
```
float num1 = 3.14;
float num2 = 2.71;
cout << (num1 & num2); // error: invalid operands to binary expression ('float' and 'float')
```
阅读全文