Learn C++ Online

C++ development environment

Write, build, run and debug C++ on your own computer with the same tools as the activities on this site.

You'll install two free applications and one extension, then download a project that's already configured. The compiler, debugger and tools run inside a container, so nothing else needs to be installed and every computer gets the same setup.

1. Install VS Code

Download Visual Studio Code for your computer and install it. On a Mac, pick the Apple Silicon or Intel download that matches your machine.

2. Install Docker Desktop

Download Docker Desktop and install it, following Docker's directions for macOS, Windows (which uses WSL 2) or Linux. Open Docker Desktop once installation finishes; it needs to be running whenever you use the environment. You don't need a Docker account.

3. Install the Dev Containers extension

Install in VS Code or install Dev Containers from the Extensions view in VS Code. It lets VS Code open a project inside the container.

4. Get a project

Any activity on this site can be downloaded as a project: click in the activity's top-right corner. Your current code is included. To start from scratch, download a starter project with a single src/main.cc:

Then open it in the container:

  1. Unzip the download.
  2. In VS Code, choose File › Open Folder… and open the unzipped folder.
  3. Click Reopen in Container when VS Code offers it, or run Dev Containers: Reopen in Container from the Command Palette (⌘⇧P on a Mac, CtrlShiftP elsewhere).

The first time takes a few minutes while Docker downloads the environment. After that, projects open in seconds.

5. Build, run and debug

Open a terminal in VS Code (Terminal › New Terminal). It runs inside the container.

  • Build: make compiles everything in src/ into bin/exec. Warnings are treated as errors, and AddressSanitizer reports memory errors when the program runs.
  • Run: ./bin/exec
  • Debug: build with make, then open Run and Debug, choose debug exec gdb and press F5. The debugger stops at the start of main and asks for any command-line arguments.
  • Start over: make clean removes the build.

6. Your own projects

Each project needs its own copy of the configuration, so start every new project from a fresh starter project download and rename the folder.

  • Put source files (.cc) in src/ and headers (.hpp) in includes/.
  • When you add a source file, add it to the bin/exec lines of the Makefile so it's compiled.
  • Keep the program at bin/exec; the debugger configuration looks for it there.