VSCode配置C/C++环境:
1、安装VSCode,直接在 官网 安装即可
2、配置C/C++环境,安装MinGW编译器,也可以在 官网 下载安装
3、MinGW编译器刚才下载的是个下载器,直接双击安装,配置X86和WIN32,指定下载目录(需要记住,之后会用,并且目录不能有空格)
4、下载完成之后,将刚才下载目录下的bin文件夹目录配置到环境变量里
5、CMD窗口输入gcc -v不报错就证明配置成功
6、VSCode中搜索C/C++扩展进行安装
7、开始配置C/C++环境:
1)VSCode中 Ctrl+Shift+P调出命令面板,输入C/C++,选择“Edit Configurations(UI)”进入配置。配置一,找到编译器路径:配置你刚才的安装路径下的g++.exe,例如 D:/mingw-w64/bin/g++.exe。 配置二,找到IntelliSense 模式:gcc-x64
2)按快捷键Ctrl+Shift+P调出命令面板,输入tasks,选择“Tasks:Configure Default Build Task”,再选择“C/C++: g++.exe build active file”。然后会产生task.json和launch.json两个文件
3)将task.json内容复制进去,记着更改目录
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++.exe build active file",
"command": "D:/ProgramFiles/MinGW-w64/mingw32/bin/g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:/ProgramFiles/MinGW-w64/mingw32/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
5)将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",
"preLaunchTask": "g++.exe build active file",
"type": "cppdbg",//只能为cppdbg
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",//调试程序的路径名称
"args": [],//调试传递参数
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "D:\\ProgramFiles\\MinGW-w64\\mingw32\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
配置完成,创建个cpp文件测试一下吧。.vscode文件夹可以先保存一份,下次可以直接复制到其他文件夹下使用。
【腾讯文档】题库
https://docs.qq.com/sheet/DVFhYbnVTY0NVdE5B