Is there a way to have multiple lines of "name = value" in an INI file using boost :: program_options :: parse_config_file?

I want to specify multiple lines of name = value in an INI file using boost::program_options . Sort of

 [list.names] name=value name=value2 name=value3 

Is there a way to achieve this with boost::program_options ? I get an error with multiple occurrences if I try to do this

If not, what other libraries are available?

+4
source share
1 answer

Specify the value of the std::vector<value_type> in options_description :

 namespace po = boost::program_options; po::options_description desc; desc.add_options() ("list.names.name", po::value< std::vector<std::string> >(), "A collection of string values"); po::variables_map vm; std::ifstream ini_file("config.ini"); po::store(po::parse_config_file(ini_file, desc), vm); po::notify(variables); if (vm.count("list.names.name")) { const std::vector<std::string>& values = vm["list.names.name"].as< std::vector<std::string> >(); std::copy(values.begin(), values.end(), std::ostream_iterator<std::string>(std::cout, "\n")); } 
+4
source

Source: https://habr.com/ru/post/1313076/


All Articles