Given that there's no answer, and given that I also had some hard hours trying to fix this, here it goes.
In Visual Studio Code the compile settings are built by default in tasks.json (Terminal > Configure Default Build Task > g++.exe ()). And in VS Code 2020 is this:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++.exe build active file",
"command": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\g++.exe",
"args": [
"-g",
"${workspaceFolder}\\*.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
(I am using mingw-64 to support gcc compiler so maybe "command" and "cwd" have different paths depending on the compiler you are using.)
The key part is this: "${file}", which is the name of the active file (active tab) in your Editor.
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
If you are working with several files, one header(.h or .hpp) and one main(.cpp) files at least, VS Code will take that active file (.h or.hpp) as it were the main file (.cpp). So you need to change it with this: "${workspaceFolder}\*.cpp".
"args": [
"-g",
"${workspaceFolder}\\*.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],