先下载vscode,下载完成后安装c/c++插件
MinGW下载地址
然后就慢慢等吧,博主安装了十几分钟。
D:\Software_install\MinGW\bin
加入系统环境变量,这时候可以cmd中运行gcc -v,如出现下图则证明MinGW安装成功
#include <iostream>
int main(){
std::cout<<("Hello,world");
return 0;
}
{
// 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": "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:\\Software_install\\MinGW\\bin\\gdb.exe",
"preLaunchTask": "g++",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
在弹出的task.json文件中将下面的代码覆盖即可,并ctrl + s 保存
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++",
"command": "D:\\Software_install\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:\\Software_install\\MinGW\\bin"
},
"problemMatcher": [
"$gcc"
]
},
{
"type": "shell",
"label": "g++.exe build active file",
"command": "D:\\Software_install\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:\\Software_install\\MinGW\\bin"
}
}
]
}
这是我的配置,你也可以覆盖后 ctrl+s 保存
{
"configurations": [
{
"name": "Win32",
"includePath": [
"D:/Software_install/MinGW/include/*",
"D:/Software_install/MinGW/lib/gcc/mingw32/8.2.0/include/*",
"D:/Software_install/MinGW/lib/gcc/mingw32/8.2.0/include/c++/*",
"D:/Software_install/MinGW/lib/gcc/mingw32/8.2.0/include/c++/mingw32/*",
"D:/Software_install/MinGW/lib/gcc/mingw32/8.2.0/include/c++/backward/*"
],
"browse": {
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "8.1",
"compilerPath": "D:/Software_install/VisualStudio/VC/bin/cl.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64"
}
],
"version": 4
}
点击vscode界面:file->Preferences->Settings->在搜索栏中搜索intelliSenseEngine->在C_Cpp.intelliSenseEngine的下拉菜单中选择Tag Parser即可,如图
可以在vscode中下载code runner插件,这样右键test.cpp,点击run code即可
vscode对于每个新文件夹都需要进行配置,所以这里建议创建了一个文件夹后先对这个文件夹进行配置,以后都在这个文件夹中建立子文件夹,或者每次创建新文件夹时将配置过的文件夹中产生的.vscode中的所有文件复制到新文件夹中再用vscode进行打开