Scenario:
1. sometimes you need to construct a command line string and pass it to the function call. For example, CreateProcess. If the parameter is dynamic, you must use STD: vector <string> to add a single parameter, concatenate the string.
Wx provides this type of processing class, namely wxw.lineparser, which can be concatenated into strings and decomposed into a parameter array.
Console. cpp
# Include "wx/wxprec. H "# ifndef wx_precomp # include" wx/wx. H "# endif # include" wx/cmdline. H "# include" wx/app. H "# include <assert. h> # include <iostream> # include <stdio. h> using namespace STD; void testparsecmdline () {cout <"testparsecmdline" <Endl; wxstring cmd ("gcc-c-o test.exe test. CPP "); // 1. parse the string wxcmdlineparser parser; // parser. setcmdline (0, (char **) null); wxarraystring arr = parser. convertstringtoargs (CMD); For (INT I = 0; I <arr. size (); ++ I) {cout <arr [I] <Endl;} // 2. generate the string parser. addparam (wxt ("GCC"); parser. addparam (wxt ("-c"); parser. addparam (wxt ("-o"); parser. addparam (wxt ("test.exe"); parser. addparam (wxt ("test. CPP "); // parser. reset (); // parser. parse (); cout <"parser. getparamcount (): "<parser. getparamcount () <Endl; For (INT I = 0; I <parser. getparamcount (); ++ I) {cout <parser. getparam (I) <Endl ;}cout <"argv:" <wxtheapp-> getappname () <Endl; wxstring STR = parser. getusagestring (); wxstring appname = wxtheapp-> getappname (); cout <"Parser:" <Str. mid (Str. find (wxtheapp-> getappname () + appname. length () + 1) <Endl;} int main (INT argc, char * argv []) {wxinitialize (); wxentrystart (argc, argv); wxinitallimagehandlers (); testparsesponline (); wxentrycleanup (); wxuninitialize (); Return 0 ;}
Output:
TestParseCmdLinegcc-c-otest.exetest.cppparser.GetParamCount(): 0argv: test_wxCmdLineParserparser: gcc -c -o test.exe test.cpp
[WxWidgets] _ [primary] _ [uncommon but practical wxw.lineparser]