Commit e7261af0 authored by Davis King's avatar Davis King

updated examples to use get_option()

parent a23adf88
......@@ -116,13 +116,9 @@ int main(int argc, char** argv)
const clp::option_type& option_in = parser.option("in");
const clp::option_type& option_out = parser.option("out");
// Figure out what the compression level should be. The default is 2.
int compression_level = 2;
// If the user supplied the -l option then use whatever value they gave for the level.
// Note that we use the string_assign object, sa, to convert the string returned
// by argument() to an int.
if (parser.option("l"))
compression_level = sa = parser.option("l").argument();
// Figure out what the compression level should be. If the user didn't supply
// this command line option then a value of 2 will be used.
int compression_level = get_option(parser,"l",2);
......
......@@ -10,7 +10,6 @@
#include "dlib/config_reader.h"
#include "dlib/string.h"
#include <iostream>
#include <fstream>
#include <vector>
......@@ -96,13 +95,18 @@ int main()
cout << cr.block("user1").block("details")["editor"] << endl;
// Note that you can use the string_assign object, sa, to easily convert fields
// into non-string types. For example, the config file has an integer id
// field that could be converted into an int like so:
int id1 = sa = cr.block("user1")["id"];
int id2 = sa = cr.block("user2")["id"];
// Note that you can use get_option() to easily convert fields into
// non-string types. For example, the config file has an integer id
// field that can be converted into an int like so:
int id1 = get_option(cr,"user1.id",0);
int id2 = get_option(cr,"user2.id",0);
cout << "user1's id is " << id1 << endl;
cout << "user2's id is " << id2 << endl;
// The third argument to get_option() is the default value returned if
// the config reader doesn't contain a corresponding entry. So for
// example, the following prints 321 since there is no user3.
int id3 = get_option(cr,"user3.id",321);
cout << "user3's id is " << id3 << endl;
}
catch (exception& e)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment