[WxWidgets] _ [primary] _ [uncommon but practical wxw.lineparser]

Source: Internet
Author: User
Tags wxwidgets


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]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.