gflags 判断一个flag是否设置

来源:互联网 发布:织梦cms使用教程 编辑:程序博客网 时间:2024/06/16 09:52
#include <iostream>#include <gflags/gflags.h>using namespace std;DEFINE_int32(port, 0, "");int main(int argc, char* argv[]) {  google::ParseCommandLineFlags(&argc, &argv, true);  google::CommandLineFlagInfo info;  if(GetCommandLineFlagInfo("port" ,&info) && info.is_default) {    cout << "port is not set!" << endl;  } else {    cout << "port is set!" << endl;  }  cout << FLAGS_port << endl;  gflags::ShutDownCommandLineFlags();  return 0;}


经常用到gflags,对于已经定义的flags,使用的时候经常需要知道是否命令行设置的值,还是使用的默认值,因为这两个在读取变量FLAGS_port的时候是无法区分的,今天找到了用于判断的api:GetCommandLineFlagInfo,mark一下

0 0
原创粉丝点击