举例: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, "=", ¶m_right); cout << "a_left=" << a << endl; cout << "a_right=" << param_right << endl; } } else { cout << "Hello World!\n"; } }View Code
执行结果:
可以看出他们被等号分离了。