C++第四十八篇 -- 字符串分离方法
举例:Test_Bluetooth.exe -param_split
Test_Bluetooth.cpp
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#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"; } }
执行结果:
可以看出他们被等号分离了。