VSCode编写C++ 无法进行调试解决方案

执行调试时,出现问题:

无法在".vscode"文件夹(Cannot read property 'name' of undefined) 内创建"launch.json"文件 

 文章进行了改进,可以转到下面链接查看改进后的文章:

https://blog.csdn.net/liu_feng_zi_/article/details/102681614

解决方法(我是这么解决的,为什么这么做可以解决,我也不知道):

 1、打开工作区的配置文件,即.code-workspace

 2、需要打开launch.json文件,但我没找到这个文件。

依次点击下图编号1,2的按钮,即出现launch.json文件

VSCode编写C++ 无法进行调试解决方案_第1张图片

3、将下面的代码,复制到launch.json文件中,其中,miDubuggerPath后的路径为C++编辑器的安装路径

{
    "version": "0.2.0",
    "configurations": [
    {
        "name": "Run C/C++",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
        "args": [],
    "stopAtEntry": false,
    "cwd": "${workspaceFolder}",
    "environment": [],
    "externalConsole": true,
    "MIMode": "gdb",
    "miDebuggerPath": "XXX/bin/gdb.exe",
    "setupCommands": [
    {
        "description": "Enable pretty-printing for gdb",
        "text": "-enable-pretty-printing",
        "ignoreFailures": false
    }
],
    "preLaunchTask": "build & run file"
},
{
    "name": "Debug C/C++",
    "type": "cppdbg",
    "request": "launch",
    "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
    "args": [],
    "stopAtEntry": false,
    "cwd": "${workspaceFolder}",
    "environment": [],
    "externalConsole": true,
    "MIMode": "gdb",
    "miDebuggerPath": "XXX/bin/gdb.exe",
    "setupCommands": [
    {
        "description": "Enable pretty-printing for gdb",
        "text": "-enable-pretty-printing",
        "ignoreFailures": false
    }
    ],
    "preLaunchTask": "build & debug file"
    }
    ]
}

4、新建tasks.json文件,将下面的代码复制进去

{
    "version": "2.0.0",
    "tasks": [
    {
        "label": "build & debug file",
        "type": "shell",
        "command": "g++",
        "args": [
            "-g",
            "-o",
            "${fileBasenameNoExtension}",
            "${file}"
    ],
    "group": {
    "kind": "build",
    "isDefault": true
    }
},
{
    "label": "build & run file",
    "type": "shell",
    "command": "g++",
    "args": [
        "-o",
        "${fileBasenameNoExtension}",
        "${file}"
    ],
    "group": {
        "kind": "build",
        "isDefault": true
        }
    }
    ]
}

5、此时,可以发现出现了两个新的配置。

VSCode编写C++ 无法进行调试解决方案_第2张图片

你可能感兴趣的:(Problem,Be,Solved)