参考资料:

  http://wiki.opencv.org.cn/index.php/Main%E5%87%BD%E6%95%B0%E5%8F%82%E6%95%B0argc%EF%BC%8Cargv%E8%AF%B4%E6%98%8E

C++语言中的main函数,经常带有参数argc,argv,如下:

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

这两个参数的作用: argc 是指命令行输入参数的个数(以空白符分隔) argv存储了所有的命令行参数 假如你的程序是hello.exe,如果在命令行运行该程序,(首先应该在命令行下用 cd 命令进入到 hello.exe 文件所在目录) 运行命令为:

hello.exe Shiqi Yu

那么,argc的值是 3,argv[0]是"hello.exe",argv[1]是"Shiqi",argv[2]是"Yu"。 

下面的程序演示argc和argv的使用:

#include <stdio.h>

int main(int argc, char ** argv)
{
int i;
for (i=0; i < argc; i++)
printf("Argument %d is %s.\n", i, argv[i]); return 0;
}

假如上述代码编译为hello.exe,那么运行

hello.exe a b c d e

将得到

Argument 0 is hello.exe.
Argument 1 is a.
Argument 2 is b.
Argument 3 is c.
Argument 4 is d.
Argument 5 is e.

运行

hello.exe lena.jpg

将得到

Argument 0 is hello.exe.
Argument 1 is lena.jpg.

最新文章

  1. 【大数据】Summingbird(Storm + Hadoop)的demo运行
  2. ios基础篇(十四)——UITableView(二)属性及基本用法
  3. android studio新项目时提示:Plugin is too old, please update to a more recent version
  4. WSB备份到远程共享文件夹的限制
  5. JavaScript 函数方法 - toString()
  6. Building Particle Filters and Particle MCMC in NIMBLE
  7. java之http协议
  8. Java作业二(2017-9-18)
  9. Zookeeper的作用,在Hadoop及hbase中具体作用
  10. Python print输出重定向到文件和屏幕,超简单
  11. hadoop HA (no zkfc to stop) DFSZKFailoverController进程没有启动
  12. beautifulSoup《转》
  13. angular7 + d3 显示svg
  14. hdu-4080 Stammering Aliens 字符串hash 模板题
  15. DB2序列和主键自增长
  16. 解决myeclipse2017安装后闪退问题
  17. WP runtime 获取cookie
  18. BZOJ4561 JLOI2016圆的异或并(扫描线+平衡树)
  19. Eclipse改变相同代码高亮颜色
  20. MongoDB(三):MongoDB概念解析

热门文章

  1. Java-main方法中调用非static方法
  2. Mac打不开inkscape怎么办
  3. [C#] 使 ToolTip 一直显示 (在 WinForm 与 WPF 中的差异解决方案)
  4. noip2019(普及组) 公交换乘 (不剪枝见祖宗题)
  5. [安卓基础] 008.Android中的显示单位
  6. ASP.NET Core 3.x API版本控制
  7. jchdl - GSL实例 - Assign
  8. Kubernetes笔记(四):详解Namespace与资源限制ResourceQuota,LimitRange
  9. Java实现 LeetCode 838 推多米诺(暴力模拟)
  10. Entity FrameWork操作数据库完成登陆、列表显示+验证码