clipp示例
clipp/1.2.3
#include <iostream> #include <string> #include <clipp.h> # define __VERSION "0.0.0.1" int main(int argc, char* argv[]) { bool help = false; bool version = false; std::string input_file; std::string output_file; auto cli = ( // 定义一个帮助标志,使用 -h 或 --help clipp::option("-h", "--help").set(help).doc("Show help information"), // 定义一个输入文件选项,使用 -i 或 --input clipp::option("-i", "--input").doc("Input file") & clipp::value("file", input_file), // 定义一个输出文件选项,使用 -o 或 --output clipp::option("-o", "--output").doc("Output file") & clipp::value("file", output_file), // 定义一个整数值选项,使用 -v 或 --value clipp::option("-v", "--value").set(version).doc("Show version") ); if (clipp::parse(argc, argv, cli)) { if (help) { std::cout << clipp::make_man_page(cli, argv[0]); }else if(version){ std::cout << "Version: " << __VERSION << std::endl; } else { std::cout << "Input file: " << input_file << std::endl; std::cout << "Output file: " << output_file << std::endl; } } else { std::cerr << clipp::make_man_page(cli, argv[0]); return 1; } return 0; }
本文作者:料峭春风吹酒醒
本文链接:https://www.cnblogs.com/pengpengda/p/18671236
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步