这是我的代码如下:
while ( ( c = getopt( argc, argv, "s:E:b:t:vh" ) ) != -1 )
{
switch ( c )
{
case 's':
params.s = atoi( optarg );
break;
case 'E':
params.E = atoi( optarg );
break;
case 'b':
params.b = atoi( optarg );
break;
case 't':
trace_file = optarg;
break;
case 'v':
verbosity = 1;
break;
}
}
但是要回答这个问题,您可以使用一堆 if/else 语句:
while ( ( c = getopt( argc, argv, "s:E:b:t:vh" ) ) != -1 )
{
if ( c == 's' )
{
params.s = atoi( optarg );
}
else if ( c == 'E' )
{
params.E = atoi( optarg );
}
else if ( c == 'b' )
{
params.b = atoi( optarg );
}
else if ( c == 't' )
{
trace_file = optarg;
}
else if ( c == 'v' )
{
verbosity = 1;
}
else
{
// always have some kind of default clause
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句