如何在 Visual Studio Code 中调试 C++ 代码

Des*_*ond 6 debugging c++14 visual-studio-code

有人使用 Visual Studio Code 进行 C++ 编程吗?请告诉我当我使用 g++ 编译器编译代码时,如何在 Visual Studio 代码中调试代码。

Ujj*_*Roy 2

用于调试项目目录中的多个 cpp 文件。

您的 launch.json 和 task.json 应该如下所示

tasks.json



{
        "type": "cppbuild",
        "label": "C/C++: g++.exe build active file",
        "command": "C:\\MinGW\\bin\\g++.exe",
        "args": [
            "-g",
            "${file}",
            "-o",
            "${fileDirname}\\${fileBasenameNoExtension}.exe"
        ],
        "options": {
            "cwd": "${workspaceFolder}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        },
        "detail": "Task generated by Debugger."
    }

launch.json

{
        "name": "g++.exe - Build and debug active file",
        "type": "cppdbg",
        "request": "launch",
        "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${fileDirname}",
        "environment": [],
        "externalConsole": false,
        "MIMode": "gdb",
        "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
        "setupCommands": [
          {
            "description": "Enable pretty-printing for gdb",
            "text": "-enable-pretty-printing",
            "ignoreFailures": true
          }
        ],
        "preLaunchTask": "C/C++: g++.exe build active file"
    }
Run Code Online (Sandbox Code Playgroud)