1.安装 mingw64,路径F:/mingw64

2.vscode安装插件

- main.cpp
cpp
// 写一个hello world程序 c++
#include <iostream>
using namespace std;
int main() {
// 返回0,表示程序正常结束
std::cout << "Hello, world!" << std::endl;
std::cout << "这是我的第一个小小小小的程序!" << std::endl;
return 0;
}
4.按下ctrl+shift+p,然后输入>C/C++

生成一个文件

c_cpp_properties.json
cpp
{
"configurations": [{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"F:/mingw64/include/**" // 根据实际安装路径修改
],
"compilerPath": "F:/mingw64/bin/g++.exe",
"intelliSenseMode": "windows-gcc-x64"
}],
"version": 4
}
lauch.json
cpp
{
"version": "0.2.0",
"configurations": [{
"name": "C++ Debug",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "gdb.exe",
"preLaunchTask": "C++ Build"
}]
}
settings.json
cpp
{
"files.associations": {
"iostream": "cpp",
"array": "cpp",
"atomic": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"optional": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"typeinfo": "cpp"
}
}
tasks.json
cpp
{
"version": "2.0.0",
"tasks": [
{
"label": "C++ Build",
"type": "shell",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.exe",
"-std=c++17",
"-Wall"
],
"group": "build"
},
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "F:/mingw64/bin/g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "F:/mingw64/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
]
}
5.运行

6.运行出来了第一个hello world!!!
