| 1 | #include <iostream>
|
|---|
| 2 | #include <sstream>
|
|---|
| 3 | #include <iterator>
|
|---|
| 4 | #include <boost/program_options.hpp>
|
|---|
| 5 | #include <boost/foreach.hpp>
|
|---|
| 6 |
|
|---|
| 7 | namespace po = boost::program_options;
|
|---|
| 8 | using namespace std;
|
|---|
| 9 |
|
|---|
| 10 | int main(int argc, char* argv[])
|
|---|
| 11 | {
|
|---|
| 12 | istringstream is("unknown_option = something_unknown"); // Input "File"
|
|---|
| 13 |
|
|---|
| 14 | po::options_description generic("Generic options");
|
|---|
| 15 | po::parsed_options parsed_file
|
|---|
| 16 | = po::parse_config_file(is, generic, true /* allow unregistered */);
|
|---|
| 17 |
|
|---|
| 18 | cout << "Unregistered options parsed...\n";
|
|---|
| 19 | vector<string>::size_type unregistered_count = 0;
|
|---|
| 20 | BOOST_FOREACH(po::option option, parsed_file.options) {
|
|---|
| 21 | if (option.unregistered) {
|
|---|
| 22 | ++unregistered_count;
|
|---|
| 23 | cout << option.string_key << ": ";
|
|---|
| 24 | ostream_iterator<string> out_it(cout, " ");
|
|---|
| 25 | copy( option.original_tokens.begin(), option.original_tokens.end(),
|
|---|
| 26 | out_it);
|
|---|
| 27 | cout << endl;
|
|---|
| 28 | }
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | cout << "\nUnrecognized options collected...\n";
|
|---|
| 32 | vector<string> unrecognized
|
|---|
| 33 | = po::collect_unrecognized(parsed_file.options, po::include_positional);
|
|---|
| 34 | BOOST_FOREACH(string option, unrecognized) {
|
|---|
| 35 | cout << option << endl;
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | return !(unregistered_count == unrecognized.size()); // 0 on pass
|
|---|
| 39 | }
|
|---|