summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/program_options/example/first.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/boost/libs/program_options/example/first.cpp')
-rw-r--r--src/boost/libs/program_options/example/first.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/boost/libs/program_options/example/first.cpp b/src/boost/libs/program_options/example/first.cpp
new file mode 100644
index 00000000..8763fec9
--- /dev/null
+++ b/src/boost/libs/program_options/example/first.cpp
@@ -0,0 +1,51 @@
+// Copyright Vladimir Prus 2002-2004.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt
+// or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+/* The simplest usage of the library.
+ */
+
+#include <boost/program_options.hpp>
+namespace po = boost::program_options;
+
+#include <iostream>
+#include <iterator>
+using namespace std;
+
+int main(int ac, char* av[])
+{
+ try {
+
+ po::options_description desc("Allowed options");
+ desc.add_options()
+ ("help", "produce help message")
+ ("compression", po::value<double>(), "set compression level")
+ ;
+
+ po::variables_map vm;
+ po::store(po::parse_command_line(ac, av, desc), vm);
+ po::notify(vm);
+
+ if (vm.count("help")) {
+ cout << desc << "\n";
+ return 0;
+ }
+
+ if (vm.count("compression")) {
+ cout << "Compression level was set to "
+ << vm["compression"].as<double>() << ".\n";
+ } else {
+ cout << "Compression level was not set.\n";
+ }
+ }
+ catch(exception& e) {
+ cerr << "error: " << e.what() << "\n";
+ return 1;
+ }
+ catch(...) {
+ cerr << "Exception of unknown type!\n";
+ }
+
+ return 0;
+}