c++ - 无法检查 VS Code 中的 C++ STL 内容
问题描述
问题陈述:
调试器无法提供 STL 容器的内容(即向量或字符串)。
概述:
下面是我launch.json
的,我-enable-pretty-printing
根据这个线程添加了,但我无法看到 STL 容器的内容。
{
"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": "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"
}
]
}
我什至尝试在监视窗口中添加表达式。但这对我也不起作用。或者,也许我错过了一些东西。这个线程
解决方案
首先,您可能使用的是 x64 Windows。
我找到了一个有效的解决方案,在 x64 Windows 中安装 MinGW 时,安装 MinGW 的i686 (win32)
版本(此评论底部给出其官方下载链接)而不是x86_64
版本,见下文:
Win32版MinGW下载:
我只是将下载的文件解压到文件夹D:\MinGW
中,然后将MinGW的bin路径添加D:\MinGW\i686-8.1.0-release-posix-dwarf-rt_v6-rev0\mingw32\bin
到PATH
环境的系统变量中。
相关配置文件如下:
.vscode\tasks.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"
}
.vscode\launch.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"
}
]
}
.vscode\c_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://github.com/microsoft/vscode-cpptools/issues/3921#issuecomment-780379258上。
愿它对你有所帮助。
推荐阅读
- javascript - 单击时如何在两个图像之间转换?
- kivy - Kivy:未知类
错误代码 - reactjs - 在渲染函数中的反应组件类中优化 var 处理
- javascript - 如何根据第一个数据列表选择链接 2 个数据列表
- javascript - 在 JS 中创建特定的实体(行)
- wix - 带有多个外部 msi 文件的 WiX BootStrapper
- jquery - 在特定区域 div 上切换类
- flutter - MethodChannel 是否会缓冲消息,直到另一端“连接”?
- c++ - C++有没有办法以同样的效率结合这个列表和映射?
- c# - 如何使 c# windows 窗体应用程序仅在单台 PC 上运行?