VScode调试C++代码时无法查看STL容器(string、vector等)

如下图所示:用VScode调试C++代码时,无法显示我们想要的值。

解决方法:编辑launch.json,加入如下设置:

"setupCommands": [
    {
        "description": "Test",
        "text": "python import sys;sys.path.insert(0, '/usr/share/gcc-8/python');from libstdcxx.v6.printers import register_libstdcxx_printers;register_libstdcxx_printers(None)",
        "ignoreFailures": false
    },
    {
        "description": "Enable pretty-printing for gdb",
        "text": "-enable-pretty-printing",
        "ignoreFailures": true
    }
]

注意:这里“/usr/share/gcc-8/python”这个路径根据每个人安装的路径不同可能会不一样的。我们得根据实际路径进行填写

 

 因为我是用VScode来进行远程调试,所以整个launch.json如下:

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [

        {
            "name": "g++ - 生成和调试活动文件",
            "type": "cppdbg",
            "request": "launch",
            "program": "/home/cjc/FUCK_TCP/FUCK_TCP/main",
            "args": [],
            "stopAtEntry": false,
            "cwd": "/home/cjc/FUCK_TCP/FUCK_TCP",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Test",
                    "text": "python import sys;sys.path.insert(0, '/usr/share/gcc-8/python');from libstdcxx.v6.printers import register_libstdcxx_printers;register_libstdcxx_printers(None)",
                    "ignoreFailures": false
                },
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],

            "preLaunchTask": "C/C++: g++ 生成活动文件",
            "miDebuggerPath": "/usr/bin/gdb",
            "miDebuggerServerAddress":"192.168.1.4:2000"
        }
    ]
}

重新按F5启动调试,我们发现可以正常显示string,vector等STL容器的值了

参考文章:

How can i see the value of elements in STL containers or arrays in debug #1414

C++ Debug Window showing "<incomplete type> for string variable

show std::string as string during debugging #201

C/C++ visualization #119

评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值