C++ Development Configuration (Windows)

Before writing code in C++, there’s a bit of configuration that needs to be done.

VS Code

VS Code is the program we’ll be using to write all of our code. It can be downloaded here. I’d recommend choosing the “User Installer” option for Windows, and be sure to only choose 64 bit if you have a 64 bit computer.

C++ Compiler

The compiler is what’s used to convert the code you write into a program your computer can run. To run your C++ code, you’ll need to download a C++ compiler that is compatible with your computer. The below steps should work as long as you’re using Windows. Otherwise, you can find additional options that are compatible with VS Code here.

  • Download MinGW-w64 (just a set of programming tools, including a C++ compiler) here, where you should be prompted to download the program.
  • Open the downloaded .exe file and complete the MinGW installation process.
    • If you’re on a 64 bit computer you can change the “i686” chipset option to “x86_64”. All other settings should be left to their defaults.
    • Keep note of your MinGW installation location; that will be used later.
  • After installation is complete (it will probably take several minutes), you need to let your computer know where its C++ compiler is located. This is done by updating your computer’s “Path” variable, which is nothing but a set of important file locations.
  • Open up the start menu and type “environment variables”. There should be an option called “Edit the system environment variables” (or something similar), which you should open.
  • Click on the button labeled “Environment Variables…”
  • Find the Path variable and double click it.
  • Click “Browse” and find the location of your MinGW installation. Then, within MinGW’s folder find a folder called “bin”. Click on it and then press “Ok”.
    • My bin folder’s path is: “C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin”, so yours may look similar.
  • Press Ok on all of the other windows you just opened to save your changes.

Configuring VS Code

Choose a place to store your C++ projects, and create a folder there (named anything) for your first program. Right click the folder and click “Open with Code”. If “Open with Code” is not an option for you, search for “Visual Studio Code” in the start menu and open the program. Then click “File” followed by “Open Folder…” and choose the folder you created.

By default, VS Code doesn’t come with great support for programming in C++, but it offers many, many extensions created by other programmers to make programming easier.

To get better C++ support, click the extensions button (the button with four white squares above) and type “c++” into the search bar. Then click on the extension called “C/C++”

Click the extension’s green “Install” button to install it.

Now we need to configure the extension a bit. Press Ctrl + Shift + P to open up the command list and type “C/C++”. Click on the option labeled “C/C++: Edit Configurations (UI)”.

Under the “Compiler path” setting, make sure the path is set to your MinGW g++.exe file.

(My exact path may look slightly different from yours. Just make sure it ends in “g++.exe”.)

Also, set the “IntelliSense mode” setting to “gcc-x64” (if you are using a 64 bit computer, “gcc-x86” if not). Then you can close out off all the tabs that are opened.

Test Code

Now it’s finally time to write some code!

In VS Code’s explorer tab, click the “New File” button next to the name of your folder (mine is called “Hello World”), and name this new file “main.cpp”.

Now copy the below code into main.cpp, and save it by pressing Ctrl + S. (I’ll go over what all this code means on the next page.)

#include <iostream>

int main() {
    std::cout << "Hello world!\n";
    return 0;
}

To compile your code (to convert it to a form readable by your computer), press Ctrl + Shift + P and find “C/C++: Build and Debug Active File”. Click on that, and then click “g++.exe – Build and debug active file”. After doing this, you’ll always be able to compile your code by simply pressing Ctrl + Shift + B.

Now the code is compiled, and you should now see a file called “main.exe” in the explorer tab. To run this file, make sure you have “cmd” selected as your current terminal by looking at the top right of your terminal tab. If the terminal is not opened, press Ctrl + ` (that second character is the backtick, on the same key as the tilde).

If “cmd” is not currently selected, you can press “Select Default Shell” and then select “Command Prompt”.

From the terminal, you can now type “.\main.exe” and your program will run! You should see “Hello world!” appear on your screen.

Later in this guide I’ll provide lots of example programs for you to try out. Just remember that, to run these programs, you’ll need to follow the steps below:

  • Save the file by pressing Ctrl + S
  • Compile the program by pressing Ctrl + Shift + B
  • Navigate to the Command Prompt and run the program by typing “.\main.exe

It’s perfectly fine if you don’t know exactly what this program is doing right now. In the next page of this C++ guide, I’ll go through the code line-by-line and explain how it all works.