參考鏈接:https://www.cnblogs.com/kileyi/p/10163269.html
舉例:Test_Bluetooth.exe -help
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 { cout << "Hello World!\n"; } }
工具是TestBluetooth.exe,參數是-help,功能是在控制台打印help。
默認執行程序不帶任何參數,會在控制台打印Hello World!。若想帶上參數-help,需要在工程屬性中設置。
右擊項目名稱 --》屬性 --》 Debugging --》Command Arguments里面填入-help。