For C++
Last updated
Last updated
First you need to install a C++ compiler. For Windows the easiest option is MinGW. Goto and select "Downloads".
Wait for SourceForge to load and select the big green button that states "Download Latest Version":
Install the package and wait for the package selector to load. Now select the "mingw32-base" and "mingw32-gcc-g++" packages and mark them for installation. From the menu select Installation => Apply Changes
to install the packages. The end result should be:
Open a powershell and make sure that the g++ --version
command gives a comparable output to the one given below:
Open Visual Studio Code and select the Extensions panel. Next install the C/C++ extension.
Launch Visual Studio Code and open a folder (this will be the root project folder). Create a new file called main.cpp
inside this folder and place the hello world code from below inside. Make sure to save it.
The end result should be this:
Next we need to create a task to build and run our application in a single step.
Hit CTRL - SHIFT - P
to open the command menu and select Tasks: Configure Task
.
Select Create tasks.json file from template
.
Choose the Others
option.
Replace the standard json config with the one from below.
Now you can select Tasks => Run Build Tasks
or hit CTRL - SHIFT - B
to build your application.
You can also select Tasks => Run Task
and select run application
to both build and run the application.
If you wish you can also define a shortcut key to run the task. Goto File => Preferences => Keyboard Shortcuts
and click the keybindings.json
tag to open the file.
Add a shortcut entry between the square brackets as shown below. Make sure to edit the file shown on the right-hand side if you get the split view (left is default example):
You can choose the key yourself and the args
is the label of the run application task.
To compile extra classes you need to add the cpp implementation file to your compilation task. For example for a file called robot.cpp
you need to add the file to the args
list of your build application
task: