VSCode配置LeetCode调试环境
目录
”工欲善其事必先利其器“
1. 插件
首先直接上 vscode官网 来安装vscode,打开vscode之后要安装几个插件,分别LeetCode、Debug LeetCode、C/C++,具体按照下图来搜索,再点击install进行安装,等安装完毕重启vscode即生效:

2.登录
有些用户在使用leetcode插件会出现登录不上,那是因为登陆节点没有选择国内,如下图先将登陆节点修改为leetcode-cn即可:

接着就是登陆账号,如下图所示,点击LeetCode Account进行账号登陆
登录成功后,这样就可以开始进行刷题,但是这个插件运行还需要nodejs来支持
3.node.js
# 更新系统包列表 sudo dnf update -y # 如果你使用的是基于Red Hat的系统如CentOS或Rocky Linux # 或者 sudo apt update # 如果你使用的是基于Debian的系统如Ubuntu # 使用NodeSource安装最新的LTS版本(例如,Node.js 18.x) curl -fsSL https://rpm.nodesource.com/setup_lts.x | sudo bash - # 对于RPM-based系统 # 或者 curl -sL https://deb.nodesource.com/setup_lts.x | sudo -E bash - # 对于Debian-based系统 # 安装Node.js sudo dnf install -y nodejs # 对于RPM-based系统 # 或者 sudo apt install -y nodejs # 对于Debian-based系统 # 验证安装 node -v npm -v
4.配置
选择C++(GDB/LLDB)进行gdb调试:
这时vscode会跳到配置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) 启动", "type": "cppdbg", "request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加) "program": "输入程序名称,例如 ${workspaceFolder}/a.exe", "args": [], "stopAtEntry": false, "cwd": "${fileDirname}", "environment": [], "externalConsole": false, // 调试时是否显示控制台窗口 "MIMode": "gdb", "miDebuggerPath": "D:/mySoftware/MinGW/bin/gdb.exe", // 修改为刚安装的MinGW/bin/gdb.exe路径 "preLaunchTask": "g++", "setupCommands": [ { "description": "为 gdb 启用整齐打印", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] } 点击下图橙色方框,即可 设置断点在 gdb 下调试代码啦
