google gflags 處理命令行參數

#include 
#include
#include

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

google gflags 處理命令行參數


./untitled --input_path="/home/Desktop" --show_flag=true --count=999

google gflags 處理命令行參數



分享到:


相關文章: