I am using boost program options to get boolean values from command line argument. I would like my argument to be specified as "Y", Yes", "N", "No".
Actually my code did it using a temporary string that
- will be parsed by
boost program options
- checked against "Y", "Yes", "N" or "No"
- assigned to the boolean variable member.
On top of that I am also using another temp string getting the default value.
I did all that work since I tried thee code below that didn't work
namespace pod = boost::program_options;
("Section.Flag",
pod::value<bool>(&myFlag_bool)->default_value( false ),
"description")
Do you know whether boost program options can be used some better then the one I use to achieve that?
You are going to be parsing a string one way or another. There are a couple options, mostly depending on how often you are going to be querying this value. Here is an example of something similar to what I recently used; CopyConstructable and Assignable so it works well with STL. I think I needed to do a few extra things to get it to work with program_options, but you get the gist: