Skip to content

Commit 524460c

Browse files
author
Sascha Ochsenknecht
committed
Enhance example, Fixes #3751, Patch from Alex Bukreev
[SVN r58289]
1 parent 388c0d1 commit 524460c

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

example/multiple_sources.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,16 @@ int main(int ac, char* av[])
2727
{
2828
try {
2929
int opt;
30+
string config_file;
3031

3132
// Declare a group of options that will be
3233
// allowed only on command line
3334
po::options_description generic("Generic options");
3435
generic.add_options()
3536
("version,v", "print version string")
36-
("help", "produce help message")
37+
("help", "produce help message")
38+
("config,c", po::value<string>(&config_file)->default_value("multiple_sources.cfg"),
39+
"name of a file of a configuration.")
3740
;
3841

3942
// Declare a group of options that will be
@@ -71,10 +74,19 @@ int main(int ac, char* av[])
7174
po::variables_map vm;
7275
store(po::command_line_parser(ac, av).
7376
options(cmdline_options).positional(p).run(), vm);
74-
75-
ifstream ifs("multiple_sources.cfg");
76-
store(parse_config_file(ifs, config_file_options), vm);
7777
notify(vm);
78+
79+
ifstream ifs(config_file.c_str());
80+
if (!ifs)
81+
{
82+
cout << "can not open config file: " << config_file << "\n";
83+
return 0;
84+
}
85+
else
86+
{
87+
store(parse_config_file(ifs, config_file_options), vm);
88+
notify(vm);
89+
}
7890

7991
if (vm.count("help")) {
8092
cout << visible << "\n";

0 commit comments

Comments
 (0)