Note that there are some explanatory texts on larger screens.

plurals
  1. PORead with boost::program_options and push_back onto std::vector?
    text
    copied!<p>I have a configuration file which contains a list of endpoint entries. Each entry is labeled with a heading of [endpt/n] (for the nth endpoint), and consists of a MAC and IP address. I'd like to use boost::program_options to read the addresses as strings, and push_back the results onto two vectors. I've looked through the program_options documentation, but I haven't been able to find what I'm looking for... Here's an example of an endpoint entry:</p> <pre><code>[endpt/2] mac=ff-22-b6-33-91-3E ip=133.22.32.222 </code></pre> <p>Here's the code I'm currently using to add each endpoint's MAC and IP options to the boost::options_description:</p> <pre><code>std::vector&lt;std::string&gt; mac(NUM_ENDPTS); std::vector&lt;std::string&gt; ip(NUM_ENDPTS); for(int e = 0; e &lt; NUM_ENDPTS; e++) { //convert endpoint 'e' to a string representing endpoint heading std::stringstream tmp; tmp.clear(); tmp.str(""); tmp &lt;&lt; e; std::string strEndpt = tmp.str(); std::string heading = "endpt/"+strEndpt; cfig_file_options.add_options() ((heading+".mac").c_str(), po::value&lt;std::string&gt;(&amp;mac[e]), ("ENDPT MAC") ((heading+".ip").c_str(), po::value&lt;std::string&gt;( &amp;ip[e]), ("ENDPT IP") ; } po::variables_map vm; po::store(po::parse_config_file(config_stream, cfig_file_options), vm); po::notify(vm); </code></pre> <p>This code works fine, but for a few reasons, I'd like to declare empty vectors for the MAC and IP addresses, and push_back the options onto them as boost reads them. I'm new to Boost, so any suggestions on better ways to read a list, or any other help would be greatly appreciated. Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload