简体   繁体   English

在 Visual Studio 代码中调试命令行

[英]Debug Command line in Visual Studio code

I am now using Visual studio code and I want to debug C/C++ program which runs as a command line.我现在正在使用 Visual Studio 代码,我想调试作为命令行运行的 C/C++ 程序。 However, debug of Visual studio code just supports the normal program (not a command line program).但是,Visual Studio 代码的调试只支持普通程序(不是命令行程序)。 When I want to debug a command line program, I need to edit my code in which I initialize the argument before running debugger.当我想调试命令行程序时,我需要在运行调试器之前编辑我在其中初始化参数的代码。 For example例如

int main(int argv, char *argc[])
{
    if (argv != 2)
    {
        printf("Wrong syntax\nCorrect Syntax: readfile <source file>\n");
        exit(1);
    }
    FILE *fp = fopen(argc[1], "rb");
}

When I want to debug, I need to initialize like this:当我想调试时,我需要像这样初始化:

int main()
{
    /*if (argv != 2)
    {
        printf("Wrong syntax\nCorrect Syntax: readfile <source file>\n");
        exit(1);
    }*/ //eliminate this part
    argc[1] = "phonebook.dat";
    FILE *fp = fopen(argc[1], "rb");

I find it annoying.我觉得很烦人。 So how do I change the debugger on VS code to debug C and C++ command line programs?那么如何更改 VS 代码上的调试器来调试 C 和 C++ 命令行程序?

You need to edit your configuration to receive command line arguments.您需要编辑配置以接收命令行 arguments。

See this: Configuring launch.json看到这个: 配置launch.json

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM