Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r58289 - trunk/libs/program_options/example
From: s.ochsenknecht_at_[hidden]
Date: 2009-12-11 08:01:32


Author: s_ochsenknecht
Date: 2009-12-11 08:01:31 EST (Fri, 11 Dec 2009)
New Revision: 58289
URL: http://svn.boost.org/trac/boost/changeset/58289

Log:
Enhance example, Fixes #3751, Patch from Alex Bukreev
Text files modified:
   trunk/libs/program_options/example/multiple_sources.cpp | 20 ++++++++++++++++----
   1 files changed, 16 insertions(+), 4 deletions(-)

Modified: trunk/libs/program_options/example/multiple_sources.cpp
==============================================================================
--- trunk/libs/program_options/example/multiple_sources.cpp (original)
+++ trunk/libs/program_options/example/multiple_sources.cpp 2009-12-11 08:01:31 EST (Fri, 11 Dec 2009)
@@ -27,13 +27,16 @@
 {
     try {
         int opt;
+ string config_file;
     
         // Declare a group of options that will be
         // allowed only on command line
         po::options_description generic("Generic options");
         generic.add_options()
             ("version,v", "print version string")
- ("help", "produce help message")
+ ("help", "produce help message")
+ ("config,c", po::value<string>(&config_file)->default_value("multiple_sources.cfg"),
+ "name of a file of a configuration.")
             ;
     
         // Declare a group of options that will be
@@ -71,10 +74,19 @@
         po::variables_map vm;
         store(po::command_line_parser(ac, av).
               options(cmdline_options).positional(p).run(), vm);
-
- ifstream ifs("multiple_sources.cfg");
- store(parse_config_file(ifs, config_file_options), vm);
         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);
+ }
     
         if (vm.count("help")) {
             cout << visible << "\n";


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk