How to Install and Set Visual Studio Code and MinGW Compiler for C and C++

To start programming in C and C++, you need a code editor and a compiler. In this guide, we will install Visual Studio Code and MinGW (GCC compiler) step-by-step.

This tutorial is beginner-friendly and ensures your system is fully ready for C/C++ development.

1. Requirements

- Windows 10/11 system

- Internet connection

- Basic knowledge of files and folders

2. Install Visual Studio Code

Step 1: Go to the official VS Code website.

Step 2: Download VS Code for Windows.

Step 3: Run the installer and follow the steps:

- Accept license agreement

- Select 'Add to PATH'

- Select 'Add Open with Code'

Step 4: Click Install and finish setup.

3. Install MinGW (GCC Compiler)

Step 1: Download MinGW from official website.

Step 2: Install MinGW and select packages:

- mingw32-gcc-g++

- mingw32-base

Step 3: Apply changes and complete installation.

4. Set Environment Variables (PATH)

Step 1: Open 'Environment Variables' in Windows.

Step 2: Edit Path variable.

Step 3: Add MinGW bin path:

TEXT
Example path
C:\MinGW\bin

Step 4: Click OK and save.

5. Verify Installation

Open Command Prompt and type:

BASH
Check compiler
g++ --version

If installed correctly, it will show version details.

6. Setup VS Code for C/C++

Step 1: Open VS Code.

Step 2: Go to Extensions (Ctrl+Shift+X).

Step 3: Install extension:

- C/C++ (by Microsoft)

Step 4: Restart VS Code.

7. Write First C++ Program

C++
Hello World
#include <iostream>
using namespace std;

int main() {
    cout << "Hello, World!";
    return 0;
}

8. Compile and Run Program

Open terminal in VS Code and run:

BASH
Compile and run
g++ main.cpp -o main
./main

9. Common Errors and Fixes

1. g++ not recognized → PATH not set correctly.

2. Permission denied → run terminal as admin.

3. Missing compiler → reinstall MinGW.

4. Incorrect file extension → use .cpp

10. Tips for Beginners

1. Practice small programs daily.

2. Learn debugging in VS Code.

3. Use shortcuts for efficiency.

4. Keep your compiler updated.

Conclusion

You have successfully installed Visual Studio Code and MinGW compiler for C and C++. Now you are ready to start coding and building applications.

Continue learning C++ concepts and practice regularly to improve your programming skills.