令牌之前的预期主表达式'='

expected primary expression before '=' token

本文关键字:表达式 令牌      更新时间:2023-10-16
#include <iostream>
using namespace std;
int main (){
int i=2 ,j =3;
      int total ;
    total + = i--;
    cout << total  << endl;
    return 0;
} 

请帮助我,我使用代码块,但我有错误

expected primary expression before '=' token )
 in  line  6  (total + = i-- )  

为什么?

它是

"+="而不是"+ ="。

就像你写"f o o"而不是"foo"一样。

你需要去掉+=之间的空格:

total += i--;