#includeint main(int argc, char** argv) { wxCmdLineParser parser; parser.AddParam("file", wxCMD_LINE_PARAM_REQUIRED); parser.Parse(argc, argv); wxString filename = parser.GetParam(0); // Use filename in some way... }
#includeThis example expects two optional positional parameters, "start" and "end". The parser is created with these parameters added, and the wxCMD_LINE_PARAM_OPTIONAL flag is used to indicate that they are not mandatory. The command line arguments are then parsed, and the values of the "start" and "end" parameters are retrieved with GetParam. If a parameter isn't present on the command line, a default value of 0 is used. Both of these examples use the wxWidgets library.int main(int argc, char** argv) { wxCmdLineParser parser; parser.AddParam("start", wxCMD_LINE_PARAM_OPTIONAL); parser.AddParam("end", wxCMD_LINE_PARAM_OPTIONAL); parser.Parse(argc, argv); int start = 0; int end = 0; if (parser.GetParamCount() >= 1) { start = wxAtoi(parser.GetParam(0)); } if (parser.GetParamCount() >= 2) { end = wxAtoi(parser.GetParam(1)); } // Use start and end in some way... }