1.首先,你得下载vscode
2.其次,你需要c++的编译运行环境
此处推荐Mingw 官网地址
3.配置C++ 的编译运行环境
在你经常要写C++项目的文件中新建文件夹.vscode
文件夹中新建3个文件
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "cmd",
"preLaunchTask": "g++",//这里需要换成你task.json中的任务名
"args": [
"/C",
"${file}.exe",
"&",
"echo.",
"&",
"pause"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole":true
}
]
}
tasks.json
{
"version": "2.0.0",
"command": "g++",
"args": ["-g","${file}","-o","${file}.exe"], // 编译命令参数
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
c_cpp_properties.json
注意: 其中的目录为你安装mingw的 路径
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceRoot}",
"D:/C++/environment/lib/gcc/mingw32/8.2.0/include/c++",
"D:/C++/environment/lib/gcc/mingw32/8.2.0/include/c++/mingw32",
"D:/C++/environment/lib/gcc/mingw32/8.2.0/include/c++/backward",
"D:/C++/environment/lib/gcc/mingw32/8.2.0/include",
"D:/C++/environment/lib/gcc/mingw32/8.2.0/include/c++/tr1",
"D:/C++/environment/mingw32/lib"
],
"defines": [
"_DEBUG",
"UNICODE",
"__GNUC__=6",
"__cdecl=__attribute__((__cdecl__))"
],
"browse": {
"path": [
"${workspaceRoot}",
"D:/C++/environment/lib/gcc/mingw32/8.2.0/include/c++",
"D:/C++/environment/lib/gcc/mingw32/8.2.0/include/c++/mingw32",
"D:/C++/environment/lib/gcc/mingw32/8.2.0/include/c++/backward",
"D:/C++/environment/lib/gcc/mingw32/8.2.0/include",
"D:/C++/environment/lib/gcc/mingw32/8.2.0/include/c++/tr1",
"D:/C++/environment/mingw32/lib"
]
},
"compilerPath": "D:\\C++\\environment\\bin\\gcc.exe",
"cStandard": "gnu18",
"cppStandard": "gnu++14"
}
],
"version": 4
}
使用结果
新建C++文件
#include<bits/stdc++.h>
using namespace std;
int main() {
cout << "hello" << endl;
return 0;
}
按F5编译运行
完美!