[英]Finding the Number of Elements in an Array of Command Line Arguments?
I'm working off of a Linux command line with g++ and the code will be executed like so: 我正在使用g ++在Linux命令行下工作,代码将像这样执行:
./mycode arg1 arg2 arg3 ...
This works fine as I am using the array argv[]
and the following for main: 当我将数组
argv[]
和以下内容用于main时,这可以正常工作:
int main (int argc, char *argv[])
However there is a part of my program where I need to know the number of command line arguments given. 但是,在程序的一部分中,我需要知道给出的命令行参数的数量 。
sizeof()
is failing me here. sizeof()
让我在这里失败。 Any ideas of how this could be accomplished? 关于如何实现的任何想法?
这就是argc
参数是为-它是的ARG umentÇ'mount argv
(ARG ument 价值)阵列。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.