A working solution for Visual Studio Code to start programming in C++.
First of all, you will need to change the path of the compiler you are going to use inside .vscode/tasks.json file:
{
"tasks": [
{
...
"command": "E:\\MinGW\\bin\\g++.exe",
...
}
]
}
In my case, I installed and used MinGW G++ compiler.
To add a class, you need to create two files and add them on src folder:
- className.cpp
- className.h
Also, you will need to add the class cpp path inside .vscode/tasks.json file:
{
"tasks": [
{
...
"args": [
"-fdiagnostics-color=always",
"-g",
"${workspaceFolder}\\src\\main.cpp",
"${workspaceFolder}\\src\\className.cpp", //your class path here
// you can add more classes here
"-o",
"${workspaceFolder}\\program.exe"
],
...
}
]
}
Compile src/main.cpp and program.exe file will be generated. Just run program.exe and you will be running the program you have just created!