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

猜你喜欢

转载自blog.csdn.net/michaelhan3/article/details/82627384