C++第四十七篇 -- VS2017带参数启动调试程序

参考链接: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";
    }
}
View Code

工具是TestBluetooth.exe,参数是-help,功能是在控制台打印help。

默认执行程序不带任何参数,会在控制台打印Hello World!。若想带上参数-help,需要在工程属性中设置。

右击项目名称 --》属性 --》 Debugging --》Command Arguments里面填入-help。

 

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