MinGW C++ 和 vscode 漂亮的打印调试不工作

MinGW C++ and vscode pretty printing debug not working

我想弄清楚为什么漂亮的打印无法正常工作。我已经查看了很多地方,试图找出它不起作用的原因,但我还没有找到解决方案。

这是问题所在:

vscode screenshot

如您所见,矢量 state 未显示其元素。这是我的 launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "gdb",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\MinGW\bin\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "build"
        }
    ]
}

这是我的 tasks.json:

{
    "tasks": [
        {
            "type": "shell",
            "label": "build",
            "command": "C:\MinGW\bin\g++.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "C:\MinGW\bin"
            }
        }
    ],
    "version": "2.0.0"
}

我让它工作了。这是救了我的post:

How to enable gdb pretty printing for C++ STL objects in Eclipse CDT?

我遵循了标记为:

的说明

这适用于使用 Eclipse 的 MinGW 用户CDT

我将 .gdbinit 放在我的 cpp 项目文件夹根目录中以供参考。