vscode+launch.json配置c++
时间: 2023-03-16 09:50:32 浏览: 97
1. 首先打开VS Code,点击左侧的“调试”按钮,然后点击“创建launch.json文件”。
2. 选择“C++”作为调试环境,然后选择“g++”作为编译器。
3. 在“launch.json”文件中添加以下代码:
{
"version": ".2.",
"configurations": [
{
"name": "C++ Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/main.cpp",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
4. 在“program”字段中输入你的C++程序的文件名,比如“main.cpp”。
5. 点击“调试”按钮,然后选择“C++ Launch”配置,就可以开始调试你的C++程序了。
相关问题
VsCode launch.json 配置
launch.json 是 VSCode 的调试配置文件,它用于配置调试器的启动参数和调试选项。下面是一个示例配置:
```
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}"
},
{
"name": "Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": [
"runserver",
"--noreload"
]
}
]
}
```
上面的配置文件中,"configurations" 数组包含了两个调试配置项,分别是 "Python: Current File" 和 "Django"。其中,"Python: Current File" 是针对当前打开的 Python 文件进行调试,"Django" 是用于调试 Django 项目。
在每个配置项中,"name" 是配置项的名称,"type" 是要使用的调试器类型,"request" 是调试器请求的类型,"program" 是要调试的程序的路径,"args" 是传递给程序的参数列表。上面的示例中,"Python: Current File" 的 "program" 使用了 VSCode 内置的变量 "${file}",表示当前打开的 Python 文件。
通过修改 launch.json 配置文件,可以实现更多的调试场景,比如调试 Node.js、Java、C++ 等语言的程序。
vscode launch.json配置c
在 VSCode 中,可以使用 launch.json 来配置 C 程序的调试选项。首先,打开调试面板 (Ctrl + Shift + D),然后点击第一个按钮,选择 C/C++ (GDB/LLDB)。这将会在工作区中创建一个 launch.json 文件。
在 launch.json 中,可以配置各种调试选项,如程序路径、编译器、调试器等。具体配置方法可以参考 VSCode 的官方文档。
示例配置:
```
{
"version": "0.2.0",
"configurations": [
{
"name": "gdb",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/main.c",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "gcc"
}
]
}
```
这样,你就可以在VSCode中调试你的C程序了。