Boost logo

Boost Users :

Subject: [Boost-users] program options parse string
From: Lloyd (lloydkl.tech_at_[hidden])
Date: 2010-12-01 04:01:44


Hi,

I want to parse a simple string using boost program options. Let the string
to parse look like this

The input string looks like this string str="ARG1=hai ARG2=long string with
space ARG3=12"

This is how the command should be parsed

ARG1="hai"
ARG2="long string with space"
ARG3=12

This is how my program looks like

string in="ARG1=hai ARG2=long string with space ARG3=12";
options_description desc("OPT");
desc.add_options()
     ("CMD",value<string>(),""),
     ("ARG",value<string>(),""),
     ("TYPE",value<int>(),"")
     ;
 variables_map vm;
stringstream ss(in);
store(parse_config_file(ss,desc),vm);
notify(vm);
if(vm.count("ARG1"))
{
      cout<<"ARG1:"<<vm["ARG1"].as<string>()<<endl;
}

But it prints ARG1:hai ARG2=long string with space ARG3=12

How can I split it into different options?

Thanks in advance,
  Lloyd



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net