C/C++ for VS Code
For the beginner ,I advise you could install a extension Code Runner
to meet demand.Don’t fool around.
Download MinGW for g++/gcc,through MSYS2 you can manage and update MinGW-w64.
Then,Configure the following three files in .vscode.
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "Build C++ file",
"type": "shell",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"group": "build",
"problemMatcher": [
"$gcc"
],
"detail": "Compiler: g++"
},
{
"type": "cppbuild",
"label": "C/C++: g++.exe generate activity files",
"command": "E:/MinGW/bin/g++.exe",//path of g++.exe
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "E:/MinGW/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "The task generated by the debugger."
}
]
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch C++ Program",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "F:\\MinGWcpp\\mingw64\\bin\\gdb.exe", //path of gdb.exe
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "Build C++ file" // consistency with the label in tasks.json
}
]
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "E:/MinGW/bin/g++.exe", //path of g++.exe
"cStandard": "c23",
"cppStandard": "gnu++23",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}