google gflags 处理命令行参数
#include <string> #include <iostream> #include <gflags/gflags.h> using namespace std; DEFINE_string(input_path, "empty" , "input file path"); DEFINE_bool(show_flag, false, "show flag"); DEFINE_int32(count, -1, "int type count "); int main(int argc, char** argv) { gflags::ParseCommandLineFlags(&argc, &argv, true); cout << "input_path = " << FLAGS_input_path << endl; cout << "show_flag = " << FLAGS_show_flag << endl; cout << "count = " << FLAGS_count << endl; gflags::ShutDownCommandLineFlags(); return 0; } cmake_minimum_required(VERSION 2.8) project(untitled) set(CMAKE_CXX_STANDARD 11) add_executable(untitled main.cpp) target_link_libraries(untitled gflags )
运行:
./untitled
./untitled --input_path="/home/Desktop" --show_flag=true --count=999
相关推荐
dxbjfu0 2020-09-11
bluecarrot 2020-08-19
zhaobig 2020-06-25
xiaohouye 2020-04-20
83520298 2020-04-16
rechanel 2020-02-28
站在高处眺望 2020-02-20
tydldd 2020-02-09
83520298 2020-01-26
83520298 2020-01-24
sunnyJam 2020-01-12
yuzhongdelei0 2019-12-31
tomson 2019-12-14
80304053 2019-12-10
qingshuoyisheng 2013-09-16
89961330 2019-11-16
invokerzhang 2019-11-10
xiejianming 2010-12-19