1. 程式人生 > >google gflags 處理命令列引數

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