g ++ expected';' 回来之前

spa*_*rky -1 c++ return g++

我得到以下代码,因为我试图了解getopt_long的用法.一切似乎都很好,但我得到"预期";' 在返回之前".我错过了什么?谢谢你们.

int next_option;
const string short_options = "a:bcde";
const struct option long_options[] = 
{
    {"op1", 1, NULL, 'a'},
    {"op2", 1, NULL, 'b'},
    {"op3", 1, NULL, 'c'},
    {"op4", 0, NULL, 'd'},
    {"op5", 0, NULL, 'e'},
    { NULL,0, NULL, 0}
};

do
{
    next_option = getopt_long(argc,argv,short_options.c_str(),long_options,NULL);

    switch(next_option)
    {
        case 'a':
        cout <<" ";
        break;

        case 'b':
        cout <<" ";
        break;

        case 'c':
        cout <<" ";
        break;

        case 'd':
        cout <<" ";
        break;

        case 'e':
        cout <<" ";
        break;

        case '?': // invalid option
        cout <<" ";
        break;

        case -1:  //no more option
        cout <<" ";
        break;

        default:
        cout <<" ";
        break;
    }

}
while(next_option!=-1)
return 0;
Run Code Online (Sandbox Code Playgroud)

为了帮助我解决这类错误,我必须遵循什么程序?

Luc*_*ore 7

我的水晶球告诉我你错过了;一个return

while(next_option!=-1); // <--- semi-colon
return 0;
Run Code Online (Sandbox Code Playgroud)


Pau*_*l R 6

错误消息告诉您问题究竟是什么 - 您丢失了;.

更改:

while(next_option!=-1)
Run Code Online (Sandbox Code Playgroud)

至:

while(next_option!=-1);
Run Code Online (Sandbox Code Playgroud)


Gra*_*and 6

你需要一个;while(next_option!=-1).

要遵循的过程是阅读错误消息,然后修复它警告你的事情(在这种情况下,丢失的分号).


Bo *_*son 6

do-while声明

do {

} while (condition);
Run Code Online (Sandbox Code Playgroud)

需要一个终止分号.就在你之前return.