TGViewer
C++ - Reddit C++ - Reddit @r_cpp · 230 subscribers
Post #25224 16
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/](https://code.visualstudio.com/)

Install normally.

# 2. Install MinGW (g++ compiler)

Download MinGW:

[https://sourceforge.net/projects/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

https://redd.it/1thf84i
@r_cpp
Visualstudio Visual Studio Code - The open source AI code editor | Your home for multi-agent development Visual Studio Code is a free, open source AI code editor. Build with AI agents that plan, code, and debug for you. Manage multi-agent workflows across environments on Linux, macOS, and Windows.
More from @r_cpp
  1. Oct 3, 2026[PLDI'26] Persistent Iterators with Value Semantics https://www.youtube.com/watch?v=cq33C5…
  2. Oct 3, 2026A Cross-Toolkit Timeline Control, Wed, Oct 14, 2026, 6:00 PM https://www.meetup.com/utah-c…
  3. Oct 3, 2026Upcoming C++ User Group meetings in October https://meetingcpp.com/meetingcpp/news/items/U…
  4. Oct 3, 2026Transcoding UTF-8 to UTF-16 with replacement at gigabytes per second https://lemire.me/blo…
  5. Oct 3, 2026EDG C++ fronted now released as open source https://edgcpp.org/#transition https://redd.it…
  6. Oct 3, 2026Arno Lepisk: Linux shared libraries https://youtu.be/IJASMkkGco8 https://redd.it/1wuvxmh @…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →