编写获取命令行参数Getopt函数(C++)
来源:互联网 发布:全国计算机考试软件 编辑:程序博客网 时间:2024/06/08 06:34
Linux系统下C++有自带的获取主函数main命令行参数的函数getopt,但在Windows系统下并没有这样的系统函数存在,不用担心,我们可以自行编写。
实例:
Project名称test
int nic_option = -1;char cont_optin = '0';char destIP_option[16] = { 0 };int getopt(int argc, char *argv[]){ // "i:r:d:" for (int i = 1; i < argc; i++) { if (!strcmp(argv[i], "-i")) // 获取整形数据 nic_option = atoi(argv[i + 1]); if (!strcmp(argv[i], "-r")) // 获取字符串或数组 sprintf(destIP_option, "%s", argv[i + 1]); if (!strcmp(argv[i], "-d")) // 获取字符 cont_optin = atoi(argv[i + 1]); } return 1;}// 主函数int main(int argc, char *argv[]){ if (getopt(argc, argv) == -1) return -1; else return -1; }
编译后生成test.exe
比如在cmd窗口输入: test.exe -i 0 -r 127.0.0.1 -d a
执行结果为:
nic_option = 0;
char cont_optin = ‘a’;
char destIP_option[16] =”127.0.0.1”;
阅读全文
0 0
- 编写获取命令行参数Getopt函数(C++)
- getopt函数--获取命令行参数
- linux获取命令行参数的函数getopt
- 获取命令行参数,getopt
- getopt函数:处理命令行参数
- getopt--命令行参数分析函数
- getopt()函数:分析命令行参数
- 分析命令行参数 (getopt函数)
- 命令行参数解析函数--getopt
- 学习解析命令行参数函数-getopt函数
- getopt function usage 获取命令行参数
- perl中Getopt::Long 获取命令行参数
- c语言学习笔记:命令行参数与命令行分析函数getopt()
- getopt(win32) -- 命令行参数解析函数
- 解析命令行选项参数的 getopt函数
- linux getopt函数 分析命令行参数
- 解析命令行选项参数函数getopt()
- 命令行参数解析函数:getopt和getopt_long
- gdb调试基本命令列表
- 关于上拉加载的一些内容
- Socket编程(网络协议一)
- 自定义邮票锯齿背景效果
- UVa 11292 贪心
- 编写获取命令行参数Getopt函数(C++)
- 利用windowManager实现App上的logcat
- Java之——类热加载
- 微信永久二维码
- 用hexo搭建个人博客上传到github上遇到的问题,
- OpenGL ES3.0 《学习笔记 六》 Vertex Attributes, Vertex Arrays, and Buffer Objects
- 解释下关于数状数组区间更新、单点查询和区间更新、区间查询
- Android使用之环境配置
- javaSwing_6事件处理机制