C getopt,有一个不需要 -x 标志的参数

C getopt, have an argument that doesn't require a -x flag

您可以使用 getopt 来解析 c 中的参数,使用包含标志的字符串,如果它们是必需的或不是,如果它们接受参数...

是否可以有一个不需要任何标志的参数,就像这样?

./program -a arg1 arg2

这里arg2不需要任何标志,但它仍然会被解析。可以用 getopt 这样做吗?

来自man 3 getopt

extern int optind;

If there are no more option characters, getopt() returns -1. Then optind is the index in argv of the first argv-element that is not an option.

如果optind小于argc,读取,自增optind,继续解析