C++第四十八篇 -- 字符串分离方法

举例:Test_Bluetooth.exe -param_split

Test_Bluetooth.cpp

#include "pch.h"
#include <iostream>
using namespace std;

void help() {
    cout << "help" << endl;
}

int main(int argc, char* argv[])
{
    if (argc == 2) {
        if (strcmp(argv[1], "-help") == 0) {
            help();
        }
        else if (strcmp(argv[1], "-param_split") == 0) {
            char a[] = "-param1=aaa";
            char* param_right;
            char *ptr = strtok_s(a, "=", &param_right);
            cout << "a_left=" << a << endl;
            cout << "a_right=" << param_right << endl;
        }
    }
    else {
        cout << "Hello World!\n";
    }
}
View Code

 

执行结果:

 

 

可以看出他们被等号分离了。

posted @ 2020-06-28 16:44  o云淡风轻o  阅读(271)  评论(0编辑  收藏  举报