Boost program_options

I understand most, mostly. However, one of their tutorials has a compile error. I'll trim the code as much as possible:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
        // Hidden options, will be allowed both on command line and
        // in config file, but will not be shown to the user.
        po::options_description hidden("Hidden options");
        hidden.add_options()
            ("input-file", po::value< vector<string> >(), "input file")
            ;
        
        
        po::variables_map vm;
        store(po::command_line_parser(ac, av).
              options(cmdline_options).positional(p).run(), vm); // ERROR: p is never defined.
        notify(vm);
        
        ifstream ifs(config_file.c_str());
        if (!ifs)
        {
            cout << "can not open config file: " << config_file << "\n";
            return 0;
        }
        else
        {
            store(parse_config_file(ifs, config_file_options), vm);
            notify(vm);
        }
 


p is a positional option, for the support of filenames without having to use a option to mark it as an input file. The code simply knows because it stands alone from any flagged option. However, in the tutorial code above, they never define p, so VC throws a compile error.

From a previous tutorial, p is declared and defined as:

1
2
3
4
5
6
7
po::positional_options_description p;
p.add("input-file", -1);

po::variables_map vm;
po::store(po::command_line_parser(ac, av).
          options(desc).positional(p).run(), vm);
po::notify(vm);


So, they declare p, then add the option "input-file". "input-file" is added in the above part, to the hidden section, but that does not make it a positional option.

This is a functionality I want to add to me project, but it doesn't help when the tut examples throw compiler errors. I'm simply not that astute with C++ and this stuff is pretty heady.

My question is: do I need to declare and define the option "input file" twice in order to define p once for inclusion in the list of options? It just seems redundant and not something I would think an ace programmer would do, but I don't really know since this is all new ground for me.
Last edited on
Topic archived. No new replies allowed.