Windows中VS code debug时无法查看C++ STL容器内容
首先,你很可能用的是x64版本的Windows。
我发现一个有效的解决方法,但在x64版本的Windows上安装MinGW时,虽然官方推荐MinGW版本的是x86_64的,但实践后发现如果选择安装 x86_64的, 很可能Debug时会无法看到STL容器(vecotr、map等)的具体信息,看到的是相应的内存地址~
故建议选 i686 (win32)
的,然后安装步骤的下一步及后面的操作都按默认的来就好。
最后的效果:
win32 版本的 MinGW官方下载地址:
我从这里下载到 MinGW 压缩包,然后解压到文件夹 D:MinGW
中,接下来把MinGW的bin目录,即 D:MinGWi686-8.1.0-release-posix-dwarf-rt_v6-rev0mingw32in
加到了系统变量的 PATH
中。
而我相应的配置文件如下:
1、.vscode asks.json
{
"tasks": [
{
// "type": "shell",
"label": "C/C++: g++.exe build active file",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
],
"version": "2.0.0"
}
2、.vscodelaunch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{ // Display content in STL containers pretty
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
3、 .vscodec_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.19041.0",
"compilerPath": "g++", // Or complete absolute path "D:/MinGW/i686-8.1.0-release-posix-dwarf-rt_v6-rev0/mingw32/bin/g++.exe"
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x86"
}
],
"version": 4
}
附上我的电脑的环境配置
VSCode Version: 1.53.2 (system setup)
OS Version: Windows 10 x64 (Windows_NT x64 10.0.19041)
MinGW version: i686-8.1.0-release-posix-dwarf-rt_v6-rev0
GDB version: 8.1.0 (Target: i686-w64-mingw32)
希望对你有用, 有问题请留言交流~
本文作者: 极客中心
原文地址: https://www.geekzl.com/windows-vs-code-cpp-stl-not-work.html
本文地址:www.geekzl.com/windows-vs-code-cpp-stl-not-work.html