Times have changed a lot since the Turbo days. And although schools and colleges are still stuck in their archaic practices, let’s see how you can run your C/C++ programs using modern tools.

What’s needed?

  1. A Compiler
  2. A Code-Editor (preferably an IDE for better QOL)

What to use?

The only absolute truth is (that development environments) change.

As the needs and goals of a project change, tools change, the best-fits for the job change.

For this particular setup geared towards beginners, we’ll be using the GNU toolchain — i.e. the gcc compiler and the de facto of today’s times, VS Code, as the code-editor.

Now the GNU toolchain isn’t native to the Windows world. To use it on Windows, we ned to use something called MinGW-w64 runtime. Let’s go ahead and grab it.

Setting up the Compiler

  1. Download the latest MinGW-w64 build from here.
    1. We need the file for a 64-bit machine, with the latest C runtime. So the filename should include keywords like win32, x86_64, and ucrt. Here’s what the filename looks like at the time of writing:
      screenshot of download section

      File to download

  2. Once the download completes, extract the zip file and move the mingw64 folder to your desired location. This is what holds your compiler.
    1. A path not too complex should be preferred.
    2. For the article’s sake, let’s just move the folder to the root of the C: drive.
  3. Add this new location to the PATH to make the compiler accessible anywhere through the command line.
  4. Launch terminal and type-in gcc --version. If done correctly, it should not error out but instead give output similar to this:
    screenshot of the terminal showing output of command

Congratulations! You just setup a compiler on your Windows machine and you can start compiling right away.

Let’s now see how to setup VS Code to go along with this.

Setting up VS Code

  1. Launch VS Code and open the folder where you’ll store and run the code from in the workspace.
    1. You can use an empty folder for this.
      screenhsot highlighting open folder option in menu
  2. Confirm the Trust Dialog since it is only you who’ll be coding there.
    screenshot of the trust dialog
  3. Since VS Code is not a complete IDE, you need extensions to get language-specific features. Here’s what’s needed for our setup: C/C++ Extension Pack and Code Runner.
    screenshot of c/++ extension pack installing
    screenshot of code runner extension page
  4. Once the extensions are installed, we need to do some project specific setup. Launch Command Pallete by hitting Ctrl+Shift+P and search for “C/C++: Edit Configurations (UI)”.
    screenshot of command pallete with the right option highlighted
  5. In the window that opens, check if your compiler is properly detected and select gcc if it’s not the selected one.
    screenshot of config editor with the right option highlighted
  6. Launch Command Pallete again. This time search for “Preferences: Open User Settings”.
  7. In the opened page, search for “code runner integrated” and tick the box that appears. This will ensure you can also receive input from the user.
    screenshot of user config editor with the right option highlighted
  8. And that’s about it. You can now run the code.
    1. Open the dropdown besides the run icon in the top-right.
    2. Select the “Run Code” option with a keyboard shortcut attached to it. This will make it the default action when you press the run button.
    3. A new terminal will pop up and the compiled executable will be run.

Happy Hacking ;)