#include #include using namespace std; void Usage(char * name); int main(int argc, char * argv[]) { string greeting{"Hello World"}; bool doHelp{false}; int i{1}; while (i < argc) { if (!strcmp(argv[i],"-h") or !strcmp(argv[i], "--help")) { doHelp = true; ++i; } else if (!strcmp(argv[i],"-G") or !strcmp(argv[i], "--greeting")) { ++i; if (i < argc) { greeting = argv[i]; ++i; } else { cerr << "Error: -g, --greeting require an additional arg" << endl; doHelp = true; } } else { cerr <<"Error: " << argv[i] << " is unknown" << endl; doHelp = true; ++i; } } if (doHelp) { Usage(argv[0]); } cout << greeting << endl; return 0; } void Usage(char * name){ cout << name << " usage: " << endl; cout << "\t -h, --help ........ Print Help" << endl; cout << "\t -G, --greeting .... Change the greeting, next arg is greeting." << endl; cout << endl; }