The first program one typically writes in any language is the "hello world" script. This example demonstrates how to write this program and debug it using Visual Studio Code (I'll refer to Visual Studio Code as VS Code from now on).
Create The Project
Step 1 will be to create a new project. This can be done in a number of ways. The first way is directly from the user interface.
From the Start menu, select New file. This will open a new editing window where we can begin constructing our script. Go ahead and save this file (you can use the menu File > Save to do this). For this example we will call the file HelloWorld.cpp and place it in a new directory which we will call VSC_HelloWorld/.
Write the program. This should be fairly straight forward, but feel free to copy the following into the file:
#include <iostream>
int main() {
std::cout << "Hello world!" << std::endl;
return 0;
}
Run the Code
Next we want to run the script and check its output. There are a number of ways to do this. The simplest is to open a terminal, and navigate to the directory that we created. You can now compile the script and run it with gcc by typing:
$ g++ HelloWorld.cpp -o helloworld
$ ./helloworld
Hello World!
Yay, the program worked! But this isn't really what we want. It would be much better if we could run the program from within VSCode itself. We're in luck though! VSCode has a built in terminal which we can access via the menu "View" > "Integrated Terminal". This will open a terminal in the bottom half of the window from which you can navigate to the VSC_HelloWorld directory and run the above commands.
Typically we do this by executing a Run Task. From the menu select "Tasks" > "Run Task...". You'll notice you get a small popup near the top of the window with an error message (something along the lines of