Visual Studio Code 下载/配置 c++环境
1. vsCode下载
2. vsCode安装
这一步反正最后一项要选,其他看自己需要
确认无误安装即可
如果你看到如下界面,那么恭喜你,你的VSCode安装完成。
3. vsCode配置
3.1 插件下载
- 必备插件
- Chinese(简体中文)——————安装完成后有右下角的提示框蓝色按钮按一下
- C/C++
- 推荐插件
- Error Lens
- Markdown Preview Enhanced
- vscode-pdf
3.2 编译器下载
TDM-GCC或MinGW都可以
Mingw
TDM-GCC
3.3 编辑系统环境变量
把编译器bin的绝对路径添加进去
打开命令行输入 gcc -v
如果在末尾显示有版本好那恭喜你,你已经成功一半了!
3.4 配置vsCode调试
- 新建文件夹
vsCode
- 在
vsCode
目录下创建两个文件夹.vscode
、code
- 在
.vscode
目录下创建三个文件c_cpp_properties.json
、launch.json
、tasks.json
,依次填充代码并根据注释更改地址
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": ["${workspaceFolder}/**"],
"defines": ["_DEBUG", "UNICODE", "_UNICODE"],
"windowsSdkVersion": "10.0.17763.0",
"compilerPath": "F:\\mingw64\\bin\\g++.exe", //将路径更改为自己编译器目录下bin文件夹里g++.exe
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "${default}"
}
],
"version": 4
}
launch.json
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "F:\\mingw64\\bin\\gdb.exe", //将路径更改为自己编译器目录下bin文件夹里gdb.exe
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "防止 gdb 打开标准库函数",
"text": "-interpreter-exec console \"skip -gfi **/bits/*.h\"",
"ignoreFailures": false
}
],
"symbolLoadInfo": {
"loadAll": false,
"exceptionList": ""
},
"preLaunchTask": "task g++"
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "task g++",
"command": "F:\\mingw64\\bin\\g++.exe", //将路径更改为自己编译器目录下bin文件夹里g++.exe
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-I",
"F:\\vsCode",
"-std=c++17"
],
"options": {
"cwd": "F:\\mingw64\\bin" //将路径更改为自己编译器目录下bin文件夹
},
"problemMatcher": [
"$gcc"
],
"group": "build"
},
{
"type": "cppbuild",
"label": "C/C++: g++.exe 生成活动文件",
"command": "F:\\mingw64\\bin\\g++.exe", //将路径更改为自己编译器目录下bin文件夹里g++.exe
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
]
}
程序放在 code
文件夹里,以后缀为.cpp
存储
按下F5调试
至此,vsCode已完成c++环境配置