【问题标题】:How does the parse_config_file of boost program options parse multitokenboost程序选项的parse_config_file如何解析multitoken
【发布时间】:2015-01-25 20:50:18
【问题描述】:

我喜欢使用带有多令牌和配置文件的 boost 程序选项来读取向量。 使用:

std::vector<int> numbers
po::options_description desc ( "Allowed Arguments" );
desc.add_options()
( "numbers,n", po::value< std::vector< int > > ( &numbers)->multitoken(), "my numbers" );

std::ifstream ifs ( "config.ini" , std::ifstream::in );
po::store ( po::parse_config_file ( ifs , desc ), vm );
po::notify ( vm );

但我现在必须在单独的行中定义 config.ini 中的每个值。喜欢

numbers = 0
numbers = 1
numbers = 3
numbers = 5

有没有一种方法/语法可以在一行中定义所有数字,例如: numbers = [0 1 3 5] # 这不起作用

谢谢 马库斯

【问题讨论】:

  • here 提供的解决方案没有帮助吗?

标签: c++ parsing syntax boost-program-options configuration-files


【解决方案1】:

根据the documentation,一行配置一个值。

但是,您可以将数字的值作为字符串读取,然后使用正则表达式或类似方法进行解析以获取各个值。

【讨论】:

  • 谢谢菲尔,我就是这样实现它的,但我希望找到更好的解决方案:-)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-07-05
  • 2012-07-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多