u/Fresh-Potato-3402

How I Set Up VS Code for Competitive Programming in C++ (Complete Beginner-Friendly Guide)

How I Set Up VS Code for Competitive Programming in C++ (Complete Beginner-Friendly Guide)

https://preview.redd.it/zs9ri9a6u12h1.png?width=1919&format=png&auto=webp&s=f443fa13437318a552ec4a9038dd8e31202963be

When I started solving DSA and Competitive Programming problems in C++, I wasted a lot of time switching between online IDEs, manually compiling code, typing input repeatedly in the terminal, and managing files poorly.

So I decided to create a proper VS Code setup for C++ development and Competitive Programming on Windows.

Now my workflow is much cleaner:

  • One-key compile and run
  • Separate folders for source code and executables
  • Input/output automation
  • Organized folder structure
  • GitHub integration
  • Clean debugging workflow

In this blog, I’ll explain everything step by step.

Step 1 — Install VS Code

Download VS Code from:

https://code.visualstudio.com/

Install it normally.

Step 2 — Install MinGW (g++ Compiler)

VS Code is just an editor.
To compile C++ programs, we need a compiler.

I installed MinGW which provides:

  • g++
  • gcc

Download MinGW:

https://sourceforge.net/projects/mingw/

While installing, make sure to select:

mingw32-gcc-g++

After installation, MinGW is usually installed here:

C:\MinGW\bin

Step 3 — Add MinGW to PATH

This step is VERY important.

Search in Windows:

Environment Variables

Open:

Edit the system environment variables

Then go to:

Environment Variables
→ Path
→ Edit
→ New

Add:

C:\MinGW\bin

Click OK everywhere.

Then restart VS Code completely.

Step 4 — Verify Compiler Installation

Open terminal in VS Code:

Ctrl + `

Run:

g++ --version

If everything is correct, you’ll see the GCC version.

Step 5 — Install Useful VS Code Extensions

I installed these extensions:

1. C/C++

Provides:

  • IntelliSense
  • Syntax highlighting
  • Debugging support

2. Code Runner (Optional)

Allows quick execution of code.

Step 6 — Create a Clean Folder Structure

I organized my DSA folder like this:

DSA/
│
├── code/
│
├── exe/
│
├── input.txt
├── output.txt
│
├── .vscode/
│   └── tasks.json
│
├── .gitignore
└── README.md

Why this structure?

  • code/ stores .cpp files
  • exe/ stores generated executables
  • input.txt contains input
  • output.txt stores output
  • .vscode/ stores VS Code automation settings

This keeps the workspace very organized.

Step 7 — Input and Output Redirection

Typing input manually in terminal again and again becomes annoying during practice.

So I used:

freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);

Now:

  • program reads from input.txt
  • output automatically goes to output.txt

This makes testing MUCH faster.

Example:

#include<bits/stdc++.h>
using namespace std;

int main(){

    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    int a,b;
    cin >> a >> b;

    cout << a + b;

    return 0;
}

Step 8 — Automating Compile and Run Using tasks.json

This was the biggest improvement in my workflow.

Instead of manually typing:

g++ file.cpp -o file.exe

every time, I automated everything using tasks.json.

Create:

.vscode/tasks.json

Paste:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Run C++",
            "type": "shell",
            "command": "cmd",
            "args": [
                "/c",
                "g++ \"${file}\" -o exe\\${fileBasenameNoExtension}.exe && exe\\${fileBasenameNoExtension}.exe"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "reveal": "always",
                "panel": "shared"
            },
            "problemMatcher": []
        }
    ]
}

Now I simply press:

Ctrl + Shift + B

and VS Code:

  • compiles current file
  • creates executable inside exe/
  • runs the program automatically

This saved me a LOT of time.

Step 9 — My VS Code Layout

I use a 3-panel layout while solving problems.

Left Side

code.cpp

Top Right

input.txt

Bottom Right

output.txt

To split the editor:

Ctrl + \

This setup feels extremely productive for CP and DSA practice.

Step 10 — GitHub Integration

I also connected my DSA folder to GitHub.

Initialize Git:

git init
git add .
git commit -m "Initial commit"

Connect GitHub repository:

git remote add origin YOUR_REPO_URL
git branch -M main
git push -u origin main

Now every solved problem is tracked on GitHub.

Step 11 — Create .gitignore

Generated .exe files should not be pushed to GitHub.

Create:

.gitignore

Add:

*.exe
output.txt

This keeps the repository clean.

Final Thoughts

After setting this up, my C++ workflow improved significantly.

Benefits:

  • faster testing
  • organized workspace
  • less repetitive work
  • cleaner debugging
  • GitHub tracking
  • better productivity during contests and DSA practice

This setup is especially useful for:

  • beginners learning C++
  • DSA practice
  • Competitive Programming
  • interview preparation

If anyone wants, I can also share:

  • my VS Code settings
  • snippets
  • debugging setup
  • CP templates
  • GitHub structure for DSA repositories
reddit.com
u/Fresh-Potato-3402 — 1 day ago
▲ 0 r/cpp_questions+1 crossposts

How I Set Up VS Code for Competitive Programming / DSA in C++ (Windows)

After trying many setups, I finally created a clean VS Code environment for C++ + Competitive Programming.

Now I have:

  • Separate folders for source code and .exe
  • One-click compile & run
  • input.txt and output.txt
  • GitHub integration
  • Clean project structure

This setup feels much better than online IDEs for serious DSA practice.

1. Install VS Code

Download:

https://code.visualstudio.com/

Install normally.

2. Install MinGW (g++ compiler)

Download MinGW:

https://sourceforge.net/projects/mingw/

While installing select:

  • mingw32-gcc-g++

After installation, your compiler path usually becomes:

C:\MinGW\bin

3. Add MinGW to PATH

Search:

Environment Variables

Open:

Edit the system environment variables

Then:

Environment Variables
→ Path
→ Edit
→ New

Add:

C:\MinGW\bin

Click OK everywhere.

Restart VS Code completely.

4. Verify Compiler

Open terminal in VS Code:

Ctrl + `

Run:

g++ --version

If installed correctly, it will show GCC version.

5. Install VS Code Extensions

Install these:

  • C/C++
  • Code Runner (optional)

6. Create Folder Structure

I use this structure:

DSA/
│
├── code/
│
├── exe/
│
├── input.txt
├── output.txt
│
├── .vscode/
│   └── tasks.json
│
├── .gitignore
└── README.md

This keeps everything clean.

7. Setup Input / Output Redirection

Inside every CPP file:

freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);

Now:

  • input comes from input.txt
  • output goes to output.txt

No need to type input repeatedly in terminal.

8. Create tasks.json for One-Key Run

Create:

.vscode/tasks.json

Paste this:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Run C++",
            "type": "shell",
            "command": "cmd",
            "args": [
                "/c",
                "g++ \"${file}\" -o exe\\${fileBasenameNoExtension}.exe && exe\\${fileBasenameNoExtension}.exe"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "reveal": "always",
                "panel": "shared"
            },
            "problemMatcher": []
        }
    ]
}

Now press:

Ctrl + Shift + B

and current file automatically:

  • compiles
  • generates .exe
  • runs

9. Recommended VS Code Layout

I split the screen into 3 sections:

Left:

code.cpp

Top-right:

input.txt

Bottom-right:

output.txt

Use:

Ctrl + \

to split editor.

This setup is AMAZING for CP practice.

10. GitHub Setup

Initialize repo:

git init
git add .
git commit -m "Initial commit"

Connect GitHub:

git remote add origin YOUR_REPO_URL
git branch -M main
git push -u origin main

Future workflow:

git add .
git commit -m "Solved new problem"
git push

11. Important .gitignore

Create:

.gitignore

Add:

*.exe
output.txt

Don’t push generated binaries.

Final Thoughts

This setup improved my workflow A LOT.

Benefits:

  • cleaner practice
  • reusable workflow
  • faster debugging
  • organized DSA repo
  • GitHub tracking
  • professional structure

If anyone wants, I can also share:

  • VS Code settings
  • debugging setup
  • contest workflow
u/Fresh-Potato-3402 — 1 day ago