c++ - 我无法在 VSCode 中调试我的 C++ 代码
问题描述
我正在尝试调试我的 C++ 文件,但是每当我按下运行 >> 开始调试选项时,它就会运行并退出而没有任何错误或任何东西。我的程序没有运行...
这是我的代码:
#include <vector>
#include <string>
#include <iostream>
using namespace std;
int main()
{
int rows, question;
std::string length;
cin >> rows;
for (int i = 0; i < rows; i++)
{
cin >> length;
}
return 0;
}
这是单击调试后在终端中显示的内容:
cmd /C "c:\Users\intel\.vscode\extensions\ms-vscode.cpptools-0.29.0\debugAdapters\bin\WindowsDebugLauncher.exe --stdin=Microsoft-MIEngine-In-oxw2rz3u.v3w --stdout=Microsoft-MIEngine-Out-5me5n3jp.wq2 --stderr=Microsoft-MIEngine-Error-wg1xnokk.ddw --pid=Microsoft-MIEngine-Pid-kfv0gezm.4wp --dbgExe=C:\MinGW\bin\gdb.exe --interpreter=mi "
C:\Users\intel\Desktop\Python programs>
这是它在输出窗口中显示的内容:
这是我的tasks.json:
{
"version": "2.0.0",
"_runner": "terminal",
"tasks": [
{
"type": "shell",
"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": "test",
"isDefault": true
}
}
]
}
这是我的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": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/a.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
}
]
},
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
},
]
}
我正在使用 Windows 机器和用于 C++ 的 MinGW
解决方案
我也使用 VSCode 在 C++ 中进行开发,但还没有尝试与 MinGW 一起使用。我将它与 MSVC 和 GCC (Linux) 一起使用。使用 GCC,我的启动配置与您的略有不同。
{
"linux": {
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing",
"text": "-enable-pretty-printing"
}
]
},
"name": "Run gcc (linux) x64 debug",
"request": "launch",
"program": "/projects/CPP/GHDWS/build/gcc-linux/x64/debug/GHDWS",
"cwd": "/projects/CPP/GHDWS/build/run",
"args": [],
"preLaunchTask": "Build gcc x64 debug",
"type": "cppdbg",
"externalConsole": false
},
我制作了自己的系统构建,它会自动为您的项目配置 VSCode。如果你愿意,你可以尝试使用它。
推荐阅读
- linux - 命令以了解文件夹中挂载的内容
- c# - 如果我多次复制,WM_DRAWCLIPBOARD 和 WM_CHANGECBCHAIN 会占用大量内存。在我的程序 C#
- bash - 终端窗口大小变化时如何触发提示重绘?
- mysql - MySQL两列复杂查询实现聊天
- sql-server - SSRS 参数值列表始终为空
- flutter - 如何在飞镖中将时间戳字符串从 24 小时格式转换为 12 小时格式?
- visual-studio-code - 无法从 VSOnline 克隆 Azure DevOps 存储库
- windows - CScript 错误:找不到脚本“C:\Program Files (x86)\Nagios\NCPA\plugins\check_files.vbs”的脚本引擎“VBScript”
- python - 在python中迭代字典时,为什么你得到键而不是键值元组?
- php - 从变体属性关系将属性分组为集合