Before configuring Visual Studio Code, a C++ compiler, debugger and the Boost C++ Libraries must be present on your system. If you haven’t installed them yet, follow the steps described here for the C++ compiler and debugger, and here for the Boost C++ Libraries.

If you have successfully installed a C++ compiler, debugger, the Boost C++ Libraries and Visual Studio Code, open Visual Studio Code, and choose the theme you want (Figure 1). Then, click on the “Mark Done” button.

Figure 1 Choosing the look you want

Click on the “Extensions” button in the Activity Bar on the left. In the Side Bar that opens, search for “C/C++ Extension Pack”, click on the “Install” button (as shown in Figure 2) and wait for the installation to complete. It is advisable to install the “C/C++ Extension Pack” that is developed by Microsoft.

Figure 2 Searching for the C/C++ Extension Pack in Visual Studio Code

Next, you must add a folder to the workspace. Click on the “Explorer” button in the Activity Bar on the left. In the Side Bar that opens, click on the “Open Folder” button, as shown in Figure 3.

Figure 3 Adding a folder to the workspace

Open (select) an empty folder where your projects should be stored. If a popup window opens asking you if you trust the authors of this folder, you should click on the “Yes, I trust the authors” button.

Notice: It is a good idea to create a folder named “VS Code CPP Projects” in your Documents folder and add that folder to the workspace.

Click on the “Explorer” button in the Activity Bar on the left and select the folder “VS Code CPP Projects”. In the Side Bar that opens, click on the “New File” option and create a file named “testingProject.cpp” (as shown in Figure 4).

Figure 4 Creating a new C++ file

With the file “testingProject.cpp” open, hit the CTRL + SHIFT + P key combination to open the Command Palette, and run the “Tasks: Configure Default Build Task” command, as shown in Figure 5.

Figure 5 Configuring the default build task

Then, select the “C/C++: g++.exe build active file” option, as shown in Figure 6. Make sure to select the g++ compiler and not the gcc one (if present)

Figure 6 Selecting the C++ Compiler

Once the “tasks.json” file is created, you should add an additional argument in the “args” section (see below). This argument is necessary so that the compiler will include the Boost C++ Library.

"-I", 
"c:\\boost"

The “tasks.json” file should look like this.

{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "cppbuild",
			"label": "C/C++: g++.exe build active file",
			"command": "C:\\msys64\\ucrt64\\bin\\g++.exe",
			"args": [
				"-fdiagnostics-color=always",
				"-g",
				"${file}",
				"-o",
				"${fileDirname}\\${fileBasenameNoExtension}.exe",
				"-I", 
				"c:\\boost"
			],
			"options": {
				"cwd": "C:\\msys64\\ucrt64\\bin"
			},
			"problemMatcher": [
				"$gcc"
			],
			"group": {
				"kind": "build",
				"isDefault": true
			},
			"detail": "compiler: \"C:\\msys64\\ucrt64\\bin\\g++.exe\""
		}
	]
}

Save the “tasks.json” file and close the corresponding tab.

Finally, you need to add some more settings. From the main menu, click on File → Preferences → Settings and click on the “Open Settings (JSON) button on the top right corner of Visual Studio Code. In the “settings.json” file that opens, add the following lines

{
    "C_Cpp.default.compilerPath": "C:\\msys64\\ucrt64\\bin\\g++.exe",
    "C_Cpp.default.includePath": ["c:\\boost"],
    "C_Cpp.clang_format_fallbackStyle": "{BasedOnStyle: LLVM, BreakBeforeBraces: Custom, BraceWrapping: {BeforeElse: true}}",
    "editor.tabSize": 2
}

Save the “settings.json” file and close the corresponding tab.

Visual Studio Code has been configured properly! Now it’s time to conquer the world of C++!