[program_options] unknown positional option
I'm having some trouble using the program_options library.
Here is some code slightly modified from an example in the documentation for
boost::program_options.
<code>
#include <iostream>
#include <vector>
#include <string>
#include
(); for (unsigned int i = 0; i < files.size(); ++i) { std::cout << "file: " << files[i] << std::endl; }
return 0;
}
</code>
Linking with version 1.40, the above code, when run with the command line
arguments "hello world", produces the following output:
<shell>
Declared positional options.
terminate called after throwing an instance of
'boost::exception_detail::clone_\
impl
Jeffrey Finkelstein wrote:
I'm having some trouble using the program_options library.
Here is some code slightly modified from an example in the documentation for boost::program_options.
<code> #include <iostream> #include <vector> #include <string> #include
#include #include namespace po = boost::program_options;
int main(int argc, char ** argv) {
po::positional_options_description desc; desc.add("files", -1); std::cout << "Declared positional options." << std::endl;
po::variables_map vm; po::store(po::command_line_parser(argc, argv).positional(desc).run(), vm);
positional_options_description merely specifies translation from position to option names. For example, the above say that every positional element of the command line is a value of an option named 'files'. However, such option still have to be declared in a regular way. - Volodya
On Thu, Aug 5, 2010 at 12:21 AM, Vladimir Prus
positional_options_description merely specifies translation from position to option names. For example, the above say that every positional element of the command line is a value of an option named 'files'. However, such option still have to be declared in a regular way.
I see. That is not clear at all in the documentation, including the
tutorial.
For reference, here's the code working with boost::program_options version
1.40.0:
<code>
#include <iostream>
#include <vector>
#include <string>
#include
(); for (unsigned int i = 0; i < files.size(); ++i) { std::cout << "file: " << files[i] << std::endl; }
return 0; } </code> Then compiling and running this program will result in: <shell> jeff@turing:~/test$ g++ -o args args.cpp -lboost_program_options jeff@turing:~/test$ ./args file1 file2 Declared positional options. Stored command line arguments into vm. Notified vm that all args have been parsed file: file1 file: file2 </shell>
Jeffrey Finkelstein wrote:
On Thu, Aug 5, 2010 at 12:21 AM, Vladimir Prus
wrote: positional_options_description merely specifies translation from position to option names. For example, the above say that every positional element of the command line is a value of an option named 'files'. However, such option still have to be declared in a regular way.
I see. That is not clear at all in the documentation, including the tutorial.
Documentation patches will be welcome. - Volodya
participants (2)
-
Jeffrey Finkelstein
-
Vladimir Prus