C ++ - INT主(INT ARGC,CHAR *的argv []) [英] C++ - int main(int argc, char *argv[])

查看:103
本文介绍了C ++ - INT主(INT ARGC,CHAR *的argv [])的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有这样的:

int main(int argc, char *argv[])

在身上,可以使用有时会发现程序的argv [1]

In the body, you can sometimes find programs using argv[1].

当我们使用的argv [1] 的argv [0] ?难道只有我们只是想读的第二的参数,在命令行?

When do we use argv[1] over argv[0]? Is it only when we just want to read the second argument in the command line?

推荐答案

按照惯例的argv [0] 当前程序的名称(或路径)和的argv [1] 的argv [ARGC - 1] 是在命令行参数用户提供。

By convention, argv[0] is the current program's name (or path), and argv[1] through argv[argc - 1] are the command-line arguments that the user provides.

不过,这并不有无的是真实的 - 程序可以OS专用功能来绕过这一要求,而这种情况往往不够,你应该意识到这一点。 (我不知道,如果有很多,即使你是意识到这一点,你可以做,但...)

However, this doesn't have to be true -- programs can OS-specific functions to bypass this requirement, and this happens often enough that you should be aware of it. (I'm not sure if there's much you can do even if you're aware of it, though...)

例如:

gcc -O3 -o temp.o "My file.c"

就(应该)产生以下参数:

would (should) produce the following arguments:

argc: 5
argv: ["gcc", "-O3", "-o", "temp.o", "My file.c"]

说着的argv [0] 将引用 GCC 的为 -O3

这篇关于C ++ - INT主(INT ARGC,CHAR *的argv [])的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆