gpt4 book ai didi

debugging - 如何在 Visual Studio Code 中调试 C++ 代码

转载 作者:行者123 更新时间:2023-12-02 23:39:59 27 4
gpt4 key购买 nike

有人使用 Visual Studio Code 进行 C++ 编程吗?请告诉我当我使用 g++ 编译器编译代码时,如何在 Visual Studio 代码中调试代码。

最佳答案

用于调试项目目录中的多个cpp文件。

你的launch.json和task.json应该是这样的

tasks.json



{
"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": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}

launch.json

{
"name": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"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"
}

关于debugging - 如何在 Visual Studio Code 中调试 C++ 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46060779/

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