[Error] expected expression before 'int'
时间: 2023-11-04 18:04:42 浏览: 183
This error occurs when there is a syntax error in the code, and the compiler is expecting an expression but instead finds the keyword "int" in the wrong place.
For example, consider the following code:
```
int main() {
int a = 5;
int b = 10;
int c = int(a + b); // Error: expected expression before 'int'
return 0;
}
```
In this code, the error occurs in the line `int c = int(a + b);`. The keyword "int" is used as if it were a function call, but it is not a valid syntax in C++. The correct way to declare and initialize the variable is simply `int c = a + b;`.
To fix the error, you need to review your code and check for any syntax errors, such as using keywords in the wrong place or missing semicolons. Correcting the syntax error should resolve the issue.
阅读全文