如何在 UStack 上实现虚拟机高可用
更新时间:2023-10-25 14:10
最新回答
required_argument(或者是1)时,参数输入格式为:--参数 值 或者 --参数=值。 optional_argument(或者是2)时,参数输入格式只能为:--参数=值。
相关问答
更多-
windows下如何实现getopt_long[2022-07-13]
解决方法是从http://directory.fsf.org/选择Software Development,然后选择GNU C的标准库,找到getopt源码,然后放到VC里编译一下,真的没别的办法 -
从手册页 : 如果该选项具有可选参数,则必须将其直接写入选项字符后(如果存在)。 您的代码按预期工作: ./a.out -c some_argument --> "C-Option: (null)" ./a.out -csome_argument --> "C-Option: some_argument" ./a.out -c=some_argument --> "C-Option: =some_argument" 您可以考虑在'='前添加可选参数名称,如上例所示。 这是另一个讨论这个问题的问题。 UP ...
-
case 'p':之前缺少break case 'p': 。 这就是控制到达port=atoi(optarg); 当“t”被处理时; 然后atoi(optarg)为非数字设备名称返回0,并将此0分配给端口。 Missing break before case 'p':. That's why control reaches port=atoi(optarg); when "t" is processed; then atoi(optarg) returts 0 for non-numeric device ...
-
getopt_long()不是C语言的一部分。 这是一个GNU发明,它在一些C实现中可用,但远不是所有。 glibc中的getopt_long()版本(在大多数Linux发行版中使用)不允许您指定必需的选项。 完成解析命令行后,您必须明确检查它们。 getopt_long() is not part of the C language. It is a GNU invention which is available in some C implementations, but far from all. ...
-
C getopt和getopt_long只适用于主参数吗?(Do C getopt and getopt_long only work for main arguments?)[2022-05-05]
getopt()和getopt_long()都适用于每个正确的char **和int , argv和任何其他char **之间没有区别。 如果你将argv和argc ,或者他们的副本从main传递给你的函数并从那里调用getopt()它将会工作。 展示你的函数如何得到argc和argv ; Both getopt() and getopt_long() will work with every proper char ** and int, there is no difference between ar ... -
Codeape, 似乎没有办法禁用缩写功能。 您并不是唯一希望获得此功能的人。 请参阅: http : //sourceware.org/bugzilla/show_bug.cgi?id = 6863 不幸的是,似乎glibc开发人员不希望选项,因为上面链接的错误报告已通过“WONTFIX”解决。 你可能在这里运气不好: - Codeape, It appears there isn't a way to disable the abbreviation feature. You aren't alone ...
-
当处理完所有选项 args时, getopt返回-1。 --stuff被认为是一个带参数的选项,在本例中是someArg1 。 someArg2 arg不以-或--开头,所以它不是一个选项。 默认情况下,这将被置换为argv的末尾。 在getopt返回-1之后,所有非选项args将在从optind到argc-1 argv : while (iarg != -1) { iarg = getopt_long(argc, argv, "s:vh", longopts, &index); // .. ...
-
编辑: “变量optind是argv中要处理的下一个元素的索引。系统将此值初始化为1.调用者可以将其重置为1以重新开始扫描相同的argv,或者扫描新的参数向量。” 所以,是的。 您可以使用getopt_long再次扫描参数或另一个参数列表。 但是,如果有人先前调用了getopt_long,则必须将全局optind变量设置为1。 请记住,main()中的argv是NULL终止的,而argc long,即; argv [argc] == NULL。 所以你可能必须确保你自己的new_argv的最后一个元素是一个 ...
-
在struct选项中设置标志时,getopt_long不返回0(getopt_long don't return 0 when have flag set in struct option)[2023-01-21]
如果您查看手册页 ,您会看到: 当识别出短选项时, getopt_long()和getopt_long_only()也返回选项字符。 对于long选项,如果flag为NULL则返回val,否则返回0。 因此,如果在调用程序时使用short选项,它将返回该选项字符。 要使函数按照您的意愿运行, 必须在调用程序时使用long参数。 If you check the manual page, you will see that: getopt_long() and getopt_long_only() also ... -
C:仅使用getopt_long作为标志,没有开关。(C: Using getopt_long for flags only, no switches. Program only sees first flag)[2022-04-12]
break在第一次迭代后停止while循环,因此它仅检查第一个选项。 我猜你最初有一个switch语句,所以break被用来退出switch并继续while循环。 由于您没有switch ,因此应该使用空的while循环。 其他事宜: 如果您不希望接受-f选项,则不应传入"f" 。 你可能还想检查'?' 返回值,表示何时使用未知选项。 The break stops the while loop after the first iteration, so it only checks the first o ...