命令行处理技术
- 命令行参数是用户在命令行中输入的参数,
- 例如:在linux中命令提示符下输入下面的命令:
wc report1 report2 report3
- c++有一种让在命令行环境中运行的程序能够访问命令行参数的机制,
int main(int argc , char *argv[])
- argc为4,argv[1]为report1,argv[2]为report2,等
- argc为命令行中参数个数,其中包括命令名本身,
- argv指针数组,指向命令行参数
vs2019中设置
- 项目属性–>调试–>命令参数
// count.cpp -- counting characters in a list of files
#include <iostream>
#include <fstream>
#include <cstdlib>//cstdlib是C++里面的一个常用函数库, 等价于C中的<stdlib.h>。
//1 字符串转换为数字的函数,包括atoi, atof, strtol等。
//2 随机数函数,包括srand, rand等。
//3 内存分配释放函数,如malloc, calloc, realloc, free等。
//4 程序运行控制函数,如exit, abort等。
//5 系统访问相关函数,如printenv,