c++ - 在Visual Studio Code中进行侦错(C++程式)时无法看到 vector 或其他容器的内容(例如 map )

标签 c++ visual-studio-code gdb visual-studio-debugging

我编写了一个简单的C++(11)程序,以在Windows的Visual Studio代码中测试调试器。我将MinGW发行版用于编译器选项。
我已经根据此处的文档设置了自己的tasks.jsonlaunch.json:
https://code.visualstudio.com/docs/cpp/config-mingw

这是示例cpp代码:

typedef std::vector<int> vi;    
int main(int argc, char const *argv[])
{
    fast();
    int tests = 1;
    cin >> tests;
    while(tests--)
    {
        int n = 5, k = 25;
        cin >> n >> k;
        vi permutation(n);
        for (int i = 0; i < n; i++)
        {
            cin >> permutation[i];
        }

        // vi permutation = {5,4,3,2,1};
        auto ans = solve(permutation, k);
       // other logic goes here

    }
    return 0;
}

我的tasks.json文件:
{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "C/C++: g++.exe build active file",
            "command": "C:\\MinGW\\bin\\g++.exe",
            "args": [
                "-g",
                "-std=c++11",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "C:\\MinGW\\bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "echo": false,
                "reveal": "always",
                "focus": true,
                "panel": "shared",
                "clear": false,
                "showReuseMessage": false
            },
        }
    ]
}

我的launch.json文件:
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++.exe - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": true,
            "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": "C/C++: g++.exe build active file"
        }
    ]
}

我在调试器窗口中看到了这一点:
enter image description here

根据文档,我应该看到类似以下的屏幕:
enter image description here

我在这里设置错误吗?为什么我看不到容器的内容?我观察到我也看不到其他容器的值。

最佳答案

从您提到的站点安装MINGW时,我遇到了同样的问题。然后我从SourceForge中提到的wiki安装了MINGW,它开始正常工作。请尝试一次。

关于c++ - 在Visual Studio Code中进行侦错(C++程式)时无法看到 vector 或其他容器的内容(例如 map ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61555313/

相关文章:

gdb 不会从外部架构读取核心文件

c++ - 如何在C++中删除一个char*数组

c++ - WinAPI:创建没有标题栏的可调整大小的窗口,但带有最小化/最大化/关闭按钮(如 Firefox/Chrome/Opera)

c++ - 将 Unicode UTF-32 文件读入 wstring

visual-studio-code - VS Code 中的终端看起来不像以前那样,需要下拉菜单

c - 为什么GDB "step"进入标准库调用的机器语言?

c++ - mysql_stmt_store_result() 上的 MySQL C API 崩溃

c++ - `C == C++` 是未定义的行为吗?

git - VS代码: git fatal error: file is outside directory

visual-studio-code - 如何在vscode中像html一样格式化svg和xml?