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.mdThis 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