“OR”令牌之前的预期非限定 ID

expected unqualified-id before ‘or’ token

本文关键字:ID OR 令牌      更新时间:2023-10-16

我在 14 种语言中收到"在'or'令牌之前出现预期的非限定 id"错误C++。我的代码如下:

#include<iostream>
using namespace std;
int main()
{  
  int s, t, a, b, m, n, count1 = 0, count2 = 0, i;
  int ap[100], or[100], ap1[100], or1[100];
  cin >> s >> t;
  cin >> a >> b;
  cin >> m >> n;
  for (i = 1; i <= m; i++)
     cin >> ap[i];
  for (i = 1; i <= n; i++)
     cin >> or[i];
  for (i = 1; i <= m; i++)
     ap1[i] = ap[i] + a;
  for (i = 1; i <= n; i++)
     or1[i] = or[i] + b;
  for (i = 1; i <= m; i++)
     if ((ap1[i] >= 7) && (ap1[i] <= 10)) 
       count1++;
  for (i = 1; i <= n; i++)
     if ((or1[i] >= 7) && (or1[i] <= 10))  
       count2++;
  cout << count1 << endl;       
  cout << count2 << endl;       
  return 0;  
}

问题是"or"是C++中的alternative operator。请参阅:https://en.cppreference.com/w/cpp/language/operator_alternative

您可能会在程序上观察到相同的错误,例如:

int main() {
    int or;
}

总之,不要尝试使用andornot等关键字作为标识符。(请参阅链接中的完整列表。