zoukankan      html  css  js  c++  java
  • [wxWidgets]_[0基础]_[不常见但有用的类wxCmdLineParser]


    场景:

    1. 有时候须要构造命令行字符串传递給函数调用,比方CreateProcess,假设參数是动态的,那么就得使用类似std::vector<string>加入单个參数,之后拼接为一个string.

    wx有给这类处理类。就是wxCmdLineParser ,它既能拼接为字符串。又能够把字符串分解为一个參数数组。


    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.解析字符串
    	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.生成字符串
    	
    	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();
    
    	TestParseCmdLine();
    
    	wxEntryCleanup();
    	wxUninitialize();
    	return 0;
    }
    
    
    
    
    

    输出:

    TestParseCmdLine
    gcc
    -c
    -o
    test.exe
    test.cpp
    parser.GetParamCount(): 0
    argv: test_wxCmdLineParser
    parser: gcc -c -o test.exe test.cpp
    




  • 相关阅读:
    Codeforces.1051G.Distinctification(线段树合并 并查集)
    BZOJ.4818.[SDOI2017]序列计数(DP 快速幂)
    BZOJ.2159.Crash的文明世界(斯特林数 树形DP)
    Codeforces.1110F.Nearest Leaf(线段树)
    Codeforces.1110E.Magic Stones(思路 差分)
    Yahoo Programming Contest 2019.D.Ears(DP)
    BZOJ.5251.[八省联考2018]劈配mentor(最大流)
    Codeforces Round #538 (Div. 2)
    BZOJ.5249.[九省联考2018]iiidx(贪心 线段树)
    Hello 2019 (D~G)
  • 原文地址:https://www.cnblogs.com/clnchanpin/p/6873060.html
Copyright © 2011-2022 走看看