gpt4 book ai didi

c++ - 如何设置 VSCode C++ 来显示局部变量

转载 作者:行者123 更新时间:2023-12-04 03:33:20 26 4
gpt4 key购买 nike

我正在关注优达学城的 C++ 纳米学位类(class)。在本类(class)中,讲师使用 VSCode、C/C++ 扩展和 Clang 格式。
enter image description here
根据类(class)说明,我已经安装了 g++ 编译器和 gdb 调试器,并且这两个工具都运行良好。我遇到的问题是,当我尝试从 VSC 进行调试时,得到的结果与 tue 讲师显示的结果完全不同。我正在使用以下代码

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
std::vector<std::string> brothers{"David", "Ethan", "Adam"};
for (std::string const &brother : brothers) {
std::cout << "Hello " << brother << "!\n";
}
}
我的调试显示了一些奇怪的信息。
enter image description here
这与教师在他的屏幕上看到的不同(他在 Linux 上)。他正在获取局部变量的实际内容。
enter image description here
这是我用于调试器的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": "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"
}
]
}
我是一名刚开始接触 C++ 的中级 Python 程序员;我的猜测是我的 VSCode 显示的是一些内存分配或类型变量的东西,但这对软件调试不是很有用。有人知道如何配置 VSCode 或编译器以正确显示变量的内容吗?我正在使用 Windows。
谢谢!
更新:
这是我的 task.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "Task generated by Debugger."
},
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file ver(1)",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "Task generated by Debugger."
},
{
"type": "cppbuild",
"label": "C/C++: cpp.exe build active file",
"command": "C:\\MinGW\\bin\\cpp.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "Task generated by Debugger."
},
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file ver(2)",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}

最佳答案

我卸载了 minGW,从这个站点安装了 MinGW-w64 http://mingw-w64.org/doku.php/download ,更改MinGW环境变量,问题解决!
enter image description here
谢谢!

关于c++ - 如何设置 VSCode C++ 来显示局部变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67464546/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com