c++ - 在VS Code调试器中更好地打印2d数组-C++

标签 c++ arrays visual-studio-code vscode-debugger

嗨,
我对VS Code上的C++编程很陌生,所以我要提出几个问题。
我的软件规格:

  • Linux,64位,深度15.9
  • VS代码1.31.1
  • G++-8,GDB 7.12
  • 使用的扩展:Microsoft
  • 的C / C++ IntelliSense,调试和代码浏览


    二维数组的C++ pretty-print

    我必须在编程时调试许多多维数组,因此我想知道一种如何在“变量”窗口(“观察”窗口也可以)中以2D形式查看2D数组的方法。矩阵。
    目前,我的变量窗口看起来像这个

    我希望它类似于

    我知道可以使用here发布的方法查看2D数组,但是我想在VSCode的debug选项卡中查看它。有没有 pretty-print 方法或代码可以帮助我实现目标?

    终端上的随机消息,当停止调试过程时

    停止C++的调试过程后,终端上会出现某种消息。这就是它的样子-

    我从打开用于调试的外部终端切换为使用内置终端,因为在停止调试过程之后,会显示上述消息,并且终端不会自动退出,因此我必须手动关闭终端。在Windows上则不是这种情况,在Windows上,终端将在调试后自动退出。有什么办法可以防止此消息(在调试完成或停止后出现)?

    我想使用外部终端进行调试,所以有什么方法可以消除此错误消息,或者在调试关闭后自动退出?

    这些是我的* .json文件

    c_cpp_properties.json
    {
        "configurations": [
            {
                "name": "Linux",
                "includePath": [
                    "${workspaceFolder}/**"
                ],
                "defines": [],
                "compilerPath": "/usr/bin/g++-8",
                "cStandard": "c11",
                "cppStandard": "c++17",
                "intelliSenseMode": "gcc-x64"
            }
        ],
        "version": 4
    }
    

    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": "(gdb) Launch",
                "type": "cppdbg",
                "request": "launch",
                "program": "${workspaceFolder}/a.out",
                "args": [],
                "stopAtEntry": false,
                "cwd": "${workspaceFolder}",
                "environment": [],
                "externalConsole": false,
                "setupCommands": [
                    {
                        "text": "-enable-pretty-printing",
                        "ignoreFailures": true
                    }
                ]
            }
        ]
    }
    

    tasks.json
    {
        // See https://go.microsoft.com/fwlink/?LinkId=733558
        // for the documentation about the tasks.json format
        "version": "2.0.0",
        "_runner": "terminal",
        "tasks": [
            {
                "label": "Build",
                "type": "shell",
                "command": "g++-8",
                "args": [
                    "-g",
                    "${file}"
                ],
                "group": {
                    "kind": "build",
                    "isDefault": true
                }
            }
        ]
    }
    

    任何帮助是真正的感谢!

    最佳答案

    我想您的选择是编写自己的gdb pretty printer或切换到lldb和以下允许高级可视化的扩展:https://github.com/vadimcn/vscode-lldb/wiki/Data-visualization

    关于c++ - 在VS Code调试器中更好地打印2d数组-C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54941596/

    相关文章:

    haskell - 无法在 Haskell 中导入模块

    php - 如何在 Vagrant (Homestead) 上使用 XDebug 和 VSCode?

    c++ - 本地定义类中的私有(private)范围

    c# - 如何解析具有交替名称行和整数列表的文本文件?

    c - 在 C 中按一个选定的属性对结构体数组进行排序

    java - 我如何改变这个java方法,不依赖lotNumber - 1

    ubuntu - 有没有办法测试 VS Code 是否在 Ubuntu 上解析我的 shell 环境?

    c++ - arm-none-eabi-g++ 调用全局构造函数

    c++ - 使用 OpenCV 进行模板匹配的图像类型问题

    c++ - const 类对象与 const 数据成员有何不同?