我得到了以下代码,因为我试图了解 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;
我必须遵循什么程序来帮助我解决此类错误?