c++ - 在 VS 代码中使用 gcc 无法看到 std::vector 的元素
问题描述
我目前正在使用 VS Code 来学习 C++,因为它易于设置并且比 VS Studio 轻得多。但是,我无法做的一件事是在调试模式下查看数组(或字符串等)的元素。
我在这里搜索了解决方案,似乎启用漂亮的打印可以解决这个问题,但不幸的是它没有(我安装了 Python 3.6)。我也尝试过使用 VS Studio 编译器和调试器,但无法让它以我想要的方式工作(基本上单击 F5 来编译单个 cpp 文件而无需更改任何选项,只需单击一下)。
你们能帮我解决这个问题吗?我目前在 Windows 10 上使用 MinGW 编译器,具有以下任务文件:
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "g++",
"args": [
"-g", "${relativeFile}", "-o", "example"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
并启动:
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/example.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"preLaunchTask": "echo",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
预先感谢!
解决方案
对我来说这可行,但首先检查你是否有'c:\msys64\mingw64\share\gcc-8.3.0\python'
或'c:\usr\share\gcc-8.3.0\python'
文件夹并调整片段
launch.json
...
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "python import sys;sys.path.insert(0, 'c:\\msys64\\mingw64\\share\\gcc-8.3.0\\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
}
],
...
推荐阅读
- java - 为什么应用程序仅在 api 26 上启动时崩溃
- python - 如何通过 Altair 图表中的条件选择部分数据
- python - 如何使用opencv检测短序列图像中的移动物体?
- c# - 屏幕截图程序过载 RAM
- php - htaccess如何删除url中的php和html
- android - App Inventor:If-Statement 会产生不良结果
- sql - 在一对多关系表中选择多条记录的单行
- java - 我正在尝试从 jsp 文件调用 servlet 来执行业务逻辑并返回同一页面
- c - 在 libusb_fill_interrupt_transfer 回调中使用“user_data”时出错
- python - 如何从 python csv 模块的第 5 行读取?