How to Set up Visual Studio Code for C and C++ Programming 2025

4 min read 2 hours ago
Published on Sep 10, 2025 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

This tutorial will guide you through the process of setting up Visual Studio Code (VSCode) for C and C++ programming on Windows. By following these steps, you'll be able to install the necessary tools and extensions to compile and run C/C++ code directly from VSCode.

Step 1: Download and Install MinGW

MinGW (Minimalist GNU for Windows) is a lightweight C/C++ compiler that you need to install first.

  1. Visit the MinGW website:

  2. Download the installer:

    • Click on the "Download" option to get the MinGW installation manager.
  3. Run the installer:

    • Follow the prompts to install MinGW. Ensure you select the following packages during installation:
      • mingw32-base (Basic MinGW)
      • mingw32-gcc-g++ (C++ Compiler)
  4. Set up the system path:

    • After installation, add MinGW to your system path:
      • Right-click on "This PC" or "My Computer" and select "Properties."
      • Click on "Advanced system settings."
      • In the System Properties window, click on "Environment Variables."
      • In the "System variables" section, find the "Path" variable and click "Edit."
      • Add the path to the MinGW bin directory (usually C:\MinGW\bin).
      • Click "OK" to save changes.

Step 2: Download and Install Visual Studio Code

Next, you need to install Visual Studio Code, which is a lightweight code editor.

  1. Go to the Visual Studio Code website:

  2. Download the installer:

    • Click the "Download" button for Windows.
  3. Install VSCode:

    • Run the downloaded installer and follow the prompts to complete the installation.

Step 3: Install the Code Runner Extension

The Code Runner extension allows you to run code snippets directly from VSCode.

  1. Open Visual Studio Code:

    • Launch the application after installation.
  2. Access the Extensions view:

    • Click on the Extensions icon on the sidebar or press Ctrl + Shift + X.
  3. Search for Code Runner:

    • In the search bar, type "Code Runner" and locate the extension by Jun Han.
  4. Install the extension:

    • Click on the "Install" button to add Code Runner to your VSCode.

Step 4: Configure VSCode for C/C++

Now, you need to set up the editor to properly compile and run C/C++ code.

  1. Open the Command Palette:

    • Press Ctrl + Shift + P to open the Command Palette.
  2. Search for and select "C/C++: Edit Configurations (UI)":

    • This will allow you to create a configuration file for compiling C/C++ code.
  3. Configure the settings:

    • In the configurations UI, set the following:
      • Compiler path: Point to the g++.exe location (usually C:\MinGW\bin\g++.exe).
      • Add any necessary flags or options you wish to use for compilation.
  4. Save your configuration:

    • Make sure to save any changes made.

Step 5: Create and Run a C/C++ Program

You are now ready to write and run your first C/C++ program.

  1. Create a new file:

    • Click on "File" > "New File" and save it with a .cpp extension for C++ (e.g., hello.cpp).
  2. Write a simple program:

    #include <iostream>
    
    int main() {
        std::cout << "Hello, World!" << std::endl;
        return 0;
    }
    
  3. Run your program:

    • To execute the code, either:
      • Right-click inside the editor and select "Run Code," or
      • Press Ctrl + Alt + N to run the code via Code Runner.

Conclusion

You have successfully set up Visual Studio Code for C and C++ programming on Windows. You installed MinGW, VSCode, and the Code Runner extension, allowing you to write and execute C/C++ code seamlessly. As a next step, consider exploring additional VSCode extensions tailored for C/C++ development or delve into more complex programming projects to enhance your skills. Happy coding!