getopt:无法识别有效的命令行参数 我是Linux环境下的C++编程,我想用GETOPT解析命令行参数。我想要一个输入-s或-q(分别为longforms--stack和--queue),而不是两者都需要,还需要一个带有必需参数的输入-o: int opt = 0, index = 0, stack=-1, map=-1; while((opt = getopt_long (argc, argv, ":sqho:", longOpts, &index)) != -1){ cout<<opt; switch(opt) { case 's': stack=0; cout << "Stack"<<stack<<"\n"; break; case 'q': stack=1; cout << "Queue"<<stack<<"\n"; //optarg is defined in getopt.h break; case 'h': cout<< "To run this program, use one of the valid cmd line args (longforms: stack, queue, help, output (M|L); shortforms: s, q, h, o (M|L), respectiely) \naccompanied with appropriate file redirection"; exit(0); break; case 'o': //opt is 'M' or 'L' cout<<"output method is: "<<optarg<<"\n"; if(*optarg=='M') map=1; else if(*optarg=='L') map=0; else map=-1; cout<<map<<"\n"; case ':': cerr<<"Map or list output must be specified as an argument to -o: "<<opt<<"\n"; case '?': cerr << "Command line error. one or more flags not recognized: " <<opt<<"\n"; //exit(1); break; } } for(int i=1; i<argc; i++){ cout<<*argv[i]<<endl; } return 0; intopt=0,index=0,stack=-1,map=-1; while((opt=getopt_long(argc,argv,“:sqho:”,longOpts和index))!=-1){ cout

getopt:无法识别有效的命令行参数 我是Linux环境下的C++编程,我想用GETOPT解析命令行参数。我想要一个输入-s或-q(分别为longforms--stack和--queue),而不是两者都需要,还需要一个带有必需参数的输入-o: int opt = 0, index = 0, stack=-1, map=-1; while((opt = getopt_long (argc, argv, ":sqho:", longOpts, &index)) != -1){ cout<<opt; switch(opt) { case 's': stack=0; cout << "Stack"<<stack<<"\n"; break; case 'q': stack=1; cout << "Queue"<<stack<<"\n"; //optarg is defined in getopt.h break; case 'h': cout<< "To run this program, use one of the valid cmd line args (longforms: stack, queue, help, output (M|L); shortforms: s, q, h, o (M|L), respectiely) \naccompanied with appropriate file redirection"; exit(0); break; case 'o': //opt is 'M' or 'L' cout<<"output method is: "<<optarg<<"\n"; if(*optarg=='M') map=1; else if(*optarg=='L') map=0; else map=-1; cout<<map<<"\n"; case ':': cerr<<"Map or list output must be specified as an argument to -o: "<<opt<<"\n"; case '?': cerr << "Command line error. one or more flags not recognized: " <<opt<<"\n"; //exit(1); break; } } for(int i=1; i<argc; i++){ cout<<*argv[i]<<endl; } return 0; intopt=0,index=0,stack=-1,map=-1; while((opt=getopt_long(argc,argv,“:sqho:”,longOpts和index))!=-1){ cout,c++,getopt,getopt-long,C++,Getopt,Getopt Long,在case'o'和case':'中缺少一个break 这会导致从o下降到:到?

case'o'
case':'中缺少一个
break

这会导致从
o
下降到