#include <fstream.h>
#include <cmdline.hh>
CmdArgInt width('w' ,"width" ,"width"
,"The width of the object");
CmdArgInt height('h' ,"height" ,"height"
,"The height of hte object",
CmdArg::isREQ | CmdArg::isVALREQ, 10);
CmdArgStr filename('f' ,"file" ,"filename" ,"The filename
to read",
CmdArg::isOPT | CmdArg::isVALREQ, "unname.txt");
int main(int argc, char* argv[])
{
CmdLine cmd(argv[0], &filename, &width, &height,
NULL);
cmd.parse(argc, argv);
ofstream infile(filename);
cout << "the file " << filename << " were
open to read." << endl;
int surface = width * height;
cout << "surface = width x height = " << width
<< " x "
<< height << "
= " << surface << endl;
return 0;
}
compilation
% g++ -I/users/silver2/projects/cgproj/package/include example1.cc -L/users/silver2/projects/cgproj/package/lib -lcmd -o example1
running examples
% example1
Error: the switch -height must be supplied
Usage: example1 -height height -width width [-file filename]
Where:
height - The height of hte
object
width - The width of
the object
filename - The filename to read
% example1 -height
Error: switch -height must take an argument
Usage: example1 -height height -width width [-file filename]
Where:
height - The height of hte
object
width - The width of
the object
filename - The filename to read
% example1 -h t
invalid integer value "t"
Error: switch -height must take an argument
Usage: example1 -height height -width width [-file filename]
Where:
height - The height of hte
object
width - The width of
the object
filename - The filename to read
% example1 -h 5 -w 3
the file unname.txt were open to read.
surface = width x height = 3 x 5 = 15
% example1 -h 5 -w 12 -f infile.dat
the file infile.dat were open to read.
surface = width x height = 12 x 5 = 60
%