getopt 分析命令行参数 -n -t 1
在Linux中,我们常常用到 ls -l 等等之类带有选项项的命令,下面,让我们用C++来实现该类似的命令。
在实现之前,首先,我们来介绍一下一个重要函数:getopt()
int main(int argc, char **argv)
{
int flag = ;
int type = ;
int opt;
while()
{
opt = getopt(argc, argv, "nt:");
if(opt == '?')
exit(EXIT_FAILURE);
else if(opt == -)
break; switch(opt)
{
case 'n':
/*printf("AAAAAAAAA\n");*/
flag |= IPC_NOWAIT;
break;
case 't':
/*printf("BBBBBBBb\n");
int n = atoi(optarg);
printf("n = %d\n", n);*/
type = atoi(optarg);
break;
}
}
}
编译完之后,我们可以使用:./a.out -n -t 1这样带有选项的命令执行
getopt 分析命令行参数 -n -t 1的更多相关文章
- 【转】getopt分析命令行参数
(一) 在Linux中,用命令行执行可执行文件时可能会涉及到给其加入不同的参数的问题,例如: ./a.out -a1234 -b432 -c -d 程序会根据读取的参数执行相应的操作,在C语言中,这个 ...
- getopt函数的使用——分析命令行参数
getopt(分析命令行参数) getopt(分析命令行参数) 短参数的定义 返回值 范例 getopt_long 相关函数表头文件#include<unistd.h> 函数声明int g ...
- getopt(分析命令行参数)
ref:http://vopit.blog.51cto.com/2400931/440453 相关函数表头文件 #include<unistd.h>定义函数 ...
- 使用getopt()处理命令行参数
假设有一程序 testopt,其命令行选项参数有: -i 选项 -l 选项 -r 选项 -n <值> 带关联值的选项 则处理 ...
- getopt解析命令行参数一例:汇集多个服务器的日志
高效工作的一个诀窍就是尽可能自动化, 简便化. 比如, 公司里, 要搜索多个集群下的应用日志来排查问题, 需要使用 pssh: pssh -i -h api_hangzhou.iplist " ...
- boost 分析命令行参数
#include <boost/program_options.hpp> #include <iostream> #include <vector> using n ...
- Python3+getopt解析命令行参数
一.说明 在学C语言的时候就知道可以通过argc获取命令行参数个数,可以通过argv获取具体参数.但自己写的程序获取到的参数一是没有键值形式二是写的参数不能乱序,和系统命令不太一样. 再往后点知道有g ...
- Shell 参数(2) --解析命令行参数工具:getopts/getopt
getopt 与 getopts 都是 Bash 中用来获取与分析命令行参数的工具,常用在 Shell 脚本中被用来分析脚本参数. 两者的比较 (1)getopts 是 Shell 内建命令,geto ...
- 转载:linux编程,命令行参数输入getopt
下面资料来自百度百科: getopt(分析命令行参数) 相关函数 表头文件 #include<unistd.h> 定义函数 int getopt(int argc,char * const ...
随机推荐
- 项目知识点.Part2
1. 取消collectionView头视图重叠情况:以下两种情况效果一样 但是有一点点bug 每次remove之后 需要把视图刷到上面才会显示(后续会改进方法) for (UIView *view ...
- CodeForces 554B(扫房间)
CodeForces 554B Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u ...
- 代码之美——Doom3源代码赏析2
http://www.csdn.net/article/2013-01-17/2813778-the-beauty-of-doom3-source-code/2 摘要:Dyad作者.资深C++工程师S ...
- Popular Deep Learning Tools – a review
Popular Deep Learning Tools – a review Deep Learning is the hottest trend now in AI and Machine Lear ...
- 通过 IDE 向 Storm 集群远程提交 topology
转载: http://weyo.me/pages/techs/storm-topology-remote-submission/ http://www.javaworld.com/article/20 ...
- poj 1273 Drainage Ditches (网络流 最大流)
网络流模板题. ============================================================================================ ...
- HDU 2255 奔小康赚大钱
题目分析:这个是个KM的模板题. #include<stdio.h> #include<string.h> #include<algorithm> #include ...
- 【转】JNI 对象处理
原文网址:http://leidiqiu.iteye.com/blog/720307 JNI 的基本问题就是解决 Java 和 C++ 代码互相调用的通信问题,在 C++ 代码编写过程中最大的问题莫过 ...
- 修改MySQL的递增的起始值
在mysql中,有时候需要把递增的值初始化为1(你也可以修改成其它起始值): alter table table_name auto_increment=; 不要设置为0......
- Andriod视频http://pan.baidu.com/share/link?shareid=7300&uk=3339495714
老罗Android开发 视频教程 一.Android入门介绍 视频教程 1.1 android系统介绍 1.3 如何搭建android开发环境 1.5 androi ...