Welcome to my first post! I will be showing you how I develop C++ using Visual Studio Code along with the C++ and Easy C++ Projects extensions.
Downloading Visual Studio Code
First we will need a code editor or IDE, I personally like Visual Studio Code (VSC for short) because it is lightweight like Sublime, but has some of the features I like from IDEs, specially Intellisense. You can download Visual Studio Code here, you will land on a page like this:
Click the download button and wait a few seconds for the download to start.
Setting up VSC for C++ development
The first time you open VSC you will see a welcome window. VSC has a very simple layout: a bar on the left with 5 buttons (File explorer, Find, Git integration, Debug, Extensions), a status bar on the bottom and a window with tabs for the editors. Click the last button to open Extensions:
To develop C++ we will install two extensions, the first one is C/C++, which is already shown in the last figure, to install it just click the green button that says
Then we will search for "easy c++" and then install the extension called "Easy C++ Projects"
Environment setup finished
After installing the extensions, a blue button will appear saying
Reload, clicking it will reload the window and activate the extensions we just installed, as shown here:
Good job! Now we have an environment for depeloping our first C++ project!
Creating our first C++ project with Visual Studio Code!
After setting up VSC for C++ development, we just need to create a new project! This is done in a few steps:
Creating a folder for the project
To set the folder for the project, go to File > Open folder (or press [Ctrl+K Ctrl+O]), a dialog like this will pop up:
Create a new folder and press "Select folder", the dialog will close and the window will reload and open the folder we have created.
Creating a C++ project
Press F1, a little window will appear with lots of different commands, search for "c++" and click "Create new C++ project":
Now we will be asked what compiler we want to use, look the Easy C++ extension page for information on how to setup a compiler for your operating system. I will use Windows Subsystem for Linux.
Now that we finished the creation step, VSC will generate the project structure for us, and open
main.cpp with some example code:
To test that the project works press the
Build & Run button on the status bar, a terminal will open and it will compile and execute our program for the first time!
Get lots of useful dev blog posts just like this one.
Sign Up Now
(open source and trusted by devs everywhere ❤️)