1.下载VScode
https://code.visualstudio.com/Download
2.安装扩展
3.下载MinGW
下载地址https://sourceforge.net/projects/mingw-w64/files/,下拉选择x86_64-posix-seh
下载下来后是一个压缩包,直接解压缩,并记住解压缩后文件的所在位置,我这里是D:\mingw64
4.配置环境变量
开始菜单里面搜索“编辑系统环境变量”
环境变量——系统变量——双击path
新建变量,输入mingw64文件下面bin文件的路径,我这里路径为D:\mingw64\bin,然后点击确定。
随后按win+R,输入cmd,回车,输入g++,回车,出现以下信息表示配置成功
随后新建一个文件夹用以存放代码
5.启动VScode
打开文件夹——选择code_file——新建一个文件helloworld.cpp,并输入以下代码,F5运行
#include <stdio.h>
#include <windows.h>
int main()
{
printf("Hello World\n");
system("pause");
return 0;
}
6.点击提示框的打开"launch.json"
用以下代码替换内容
{
"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": "D:\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "task g++" //修改此项
}
]
}
随后F5运行
7.点击提示框中的"配置任务"
使用模板创建——Others——创建一个tasks.json,并用以下代码替换内容
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "task g++",
"command": "D:\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
}
]
}