目录
- 下载vscode
- 安装相关拓展插件
- 下载编辑器
- 环境配置
- 配置.vscode文件
- 新建调试
1.下载vscode
-
对应自己电脑的版本去下载即可,挺方便的
-官方下载地址:https://code.visualstudio.com/#alt-downloads -
vscode设置中文环境教程
http://www.chuancn.cn/post/将VSCode设置成中文语言环境
2、安装相关拓展插件
- 在拓展商店里搜索安装C/C++插件
- 安装完之后记得重启
3.下载编辑器
-
下载MinGW-W64 GCC-8.1.0编译器
官网下载地址
具体可按自己需要情况而定,一般推荐下载压缩包,速度快(×86_64-posix-sjlj)
-
下载到自己相应的文件路径下,我一般下载在x86文件夹下,然后将压缩包解压到当前目录下
- 打开文件夹里的bin目录,并复制该bin路径留作配置环境变量用
4.配置path变量
- 搜索此电脑,找到并打开属性
- 点击高级系统设置
- 点击环境变量
- 找到path并编辑 和新建
- 把下载的MinGW里的bin目录路径粘贴在这里
- 检查有没有配置成功
输入g++ -v
出现上述图片说明配置成功
5.配置.vscode文件
- 首先新建文件夹(文件夹名字一定要是英文的,要不然后面编译出问题)
- 在该文件夹下创建一个.vscode文件夹工作空间,并创建三个文件,分别是c_cpp_properties.json,launch.json,tasks.json(记得ctr+f去替换成自己的bin路径)
- c_cpp_properties.json
{
"configurations": [
{
"name": "Win64",
"includePath": [
"${workspaceFolder}/**",
"C:/Program Files (x86)/C++环境/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.4.0/include",
"C:/Program Files (x86)/C++环境/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.4.0/include-fixed",
"C:/Program Files (x86)/C++环境/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.4.0/../../../../x86_64-w64-mingw32/include",
"C:/Program Files (x86)/C++环境/mingw64/lib/gcc/../../x86_64-w64-mingw32/include/c++",
"C:/Program Files (x86)/C++环境/mingw64/lib/gcc/../../x86_64-w64-mingw32/include/c++/x86_64-w64-mingw32",
"C:/Program Files (x86)/C++环境/mingw64/lib/gcc/../../x86_64-w64-mingw32/include/c++/backward"
],
"defines": ["_DEBUG", "UNICODE", "_UNICODE"],
"windowsSdkVersion": "10.0.17763.0",
"compilerPath": "C:\\Program Files (x86)\\C++环境\\mingw64\\bin\\g++.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "${default}"
}
],
"version": 4
}
includepath里的内容从(g++ -v -E -x c++ -)命令打开的cmd里复制过去
- 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": "C:\\Program Files (x86)\\C++环境\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "task g++"
}
]
}
- tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "task g++",
"command": "C:\\Program Files (x86)\\C++环境\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-I",
"C:\\Users\\86198\\Desktop\\力扣刷题冲冲冲\\vsCode",
"-std=c++17"
],
"options": {
"cwd": "C:\\Program Files (x86)\\C++环境\\mingw64\\bin"
},
"problemMatcher":[
"$gcc"
],
"group": "build",
}
]
}
6. 新建调试
- 在新建的文件夹下新建一个cpp文件(注意一定要是英文名,不可以出现中文会报错的!)
#include <stdio.h>
#include <windows.h>
int main()
{
printf("Hello World\n");
system("pause");
return 0;
}
- 调试运行 成功!!
最后
- 新建的文件夹路径一定要是全英文
- 文件夹下新建的cpp一定也要是全英文
- 如果include报错就是includepath少东西
- 有什么遗漏的可以去官方文档里查找一下
- 接下来就可以开启我们的c++开发之旅啦!