next up previous contents index Api Refernce
Next: 2 Contact the author Up: 1 Introduction Previous: 1.1 Overview


1.2 A simple sample

This is the source code of a working simple sample:

#include <string>
#include <iostream>
#include "cmdline.h"

using namespace std;
using namespace cmdl;

int main( int argc, char *argv[] )
{
    // parse command line
    try {
	CmdLine C;
	C.Init( --argc, ++argv); // mark the command line arguments
	                         // to be parsed (without program name)

        // retrieve and print an integer set with option "--set-int"
	int nTest = 0; 
	C.GetSingleValue("--set-int", nTest);
	cout << "Integer set: " << nTest << endl;

	C.Done(); // check for unused options
    }

    // handle errors
    catch (exception& e){
	cout << e.what() << endl;
    }
}


Executing the program above looks like this:

> cmdsample --set-int 117
Integer set: 117

More examples are found in chapter usage.


next up previous contents index Api Refernce
Next: 2 Contact the author Up: 1 Introduction Previous: 1.1 Overview
Christian Neise
2003-01-12