gpt4 book ai didi

c++ - ‘or’ token 之前的预期不合格 ID

转载 作者:行者123 更新时间:2023-11-28 01:25:07 25 4
gpt4 key购买 nike

我在 C++ 14 语言中收到“expected unqualified-id before ‘or’ token”错误。我的代码如下:

#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;
}

最佳答案

问题是“或”是C++ 中的替代运算符。请参阅:https://en.cppreference.com/w/cpp/language/operator_alternative

您可以通过如下简单的程序观察到相同的错误:

int main() {
int or;
}

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

关于c++ - ‘or’ token 之前的预期不合格 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54200749/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com