extern void GetAllFlags(std::vector<CommandLineFlagInfo>* OUTPUT)接口

示例代码:

#include "bits/stdc++.h"
#include <gflags/gflags.h>
#include "flags.h"

using namespace std;

DEFINE_int32(portno, 0, "portno,默认为0");

int main(int argc, char* argv[])
{
    google::SetVersionString("V1.0.0@const.net.cn");
    google::SetUsageMessage("-help ");
    google::ParseCommandLineFlags(&argc, &argv, true);

    std::vector<google::CommandLineFlagInfo> OUTPUT;
    GetAllFlags(&OUTPUT);
    for(auto i=0;i<OUTPUT.size();i++)
    {
        cout<<OUTPUT[i].name<<"="<<OUTPUT[i].current_value<<endl;
    }
    return 0;
}

 ./test_gflags -portno=11

flagfile=
fromenv=
tryfromenv=
undefok=
tab_completion_columns=80
tab_completion_word=
help=false
helpfull=false
helpmatch=
helpon=
helppackage=false
helpshort=false
helpxml=false
version=false
bool_var=true
double_var=0
int32_var=0
int64_var=0
string_var=
uint32_var=0
uint64_var=0
portno=11

本文链接地址:https://const.net.cn/563.html

标签: gflags

添加新评论