简体   繁体   English

主表达式C ++错误

[英]Primary expression C++ error

I have to write some programs for a class final and I'm running into an error that I can't figure out. 我必须为决赛课程编写一些程序,但遇到了无法解决的错误。 I have checked the syntax in this program many times and it isn't very long so I don't know why I can't find it. 我已经在该程序中检查了很多次语法,而且时间不长,所以我不知道为什么找不到它。 When I try and compile, I get an error that says "expected primary-expression before '}' token". 尝试编译时,出现错误,提示“'}'标记之前有预期的主表达式”。 It says it's in line 23. Can anyone shed some light on what might be going on? 它说它在第23行。任何人都可以对可能发生的事情有所了解吗?

#include <iostream>
using namespace std;

int main()
{
    int sumOfPrimes = 2;

    for (int x=3; x<2000000; x++)
    {
        for (int y=2; y<x; y++)
        {
            if (x % y == 0)
            {
                goto break1;
            }
        }
        sumOfPrimes += x;
        break1:
    }

    cout << sumOfPrimes << endl;

    return 0;
}

You need to add a statement after a label. 您需要在标签后添加一条语句 The null statement ; 空语句; works fine: 工作正常:

break1: ;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM