ArgumentList 0.1
Some times ago I was reading the book “An Introduction to Design Patterns in C++ with Qt 4” and I found really useful for lazy peoples like me the utility for easily access command line argument list parameters in C++ with the use of QT framework.
So I decided to write from scratch a similar code, but in pure C++.
Using it is quite simple, as you can read in the test available in the package and here:
#include "ArgumentList.h"
#include
using namespace sclocco;
using std::cout;
using std::cin;
using std::endl;
using std::string;
int main(int argc, char *argv[]) {
ArgumentList args = ArgumentList(argc, argv);
string input = "";
char again = 'Y';
cout << "Testing utility for ArgumentList class." << endl;
while ( again == 'Y' ) {
cout << "Do you want to search for a switch, for the argument of a switch or the first remaining argument (1/2/3): ";
cin >> input;
if ( input.compare("1") == 0 ) {
cout << "Insert the switch: ";
cin >> input;
if ( args.getSwitch(input) ) {
cout << "Switch \"" << input << "\" found." << endl;
}
else {
cout << "Switch\ "" << input << "\" not found." << endl;
}
}
else if ( input.compare("2") == 0 ) {
string temp = "";
cout << "Insert the switch: ";
cin >> input;
temp = args.getSwitchArgument(input);
cout << "The argument of switch \"" << input << "\" is: " << temp << endl;
}
else if ( input.compare("3") == 0 ) {
cout << "The first remaining argument is: " << args.getFirst() << endl;
}
cout << "Continue testing (Y/N): ";
cin >> again;
}
return 0;
}
If you want to try it download the package here.
Related posts: