This guide explains how to set up a competitive programming environment in Linux using VS Code and Sublime Text.
For the Windows setup, refer to this link.
- Open the folder where you have your executable files in VS Code.
- Inside this folder, create a
.vscode
folder. - Within the
.vscode
folder, create two files:launch.json
andtasks.json
.
Copy and paste the following content into your launch.json
file:
{
"version": "0.2.0",
"configurations": [
{
"name": "Run C++",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"preLaunchTask": "Compile and Run",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
Copy and paste the following content into your tasks.json
file:
{
"version": "2.0.0",
"tasks": [
{
"label": "Compile and Run",
"type": "shell",
"command": "bash",
"args": [
"-c",
"g++ -g -DDEBUG ${relativeFile} -o ${fileBasenameNoExtension}.out && ./${fileBasenameNoExtension}.out < input.txt > output.txt && rm ${fileBasenameNoExtension}.out"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
]
}
- Update
input.txt
andoutput.txt
in thetasks.json
file to the names of your input and output files. - Replace
-DDEBUG
with a custom macro name.
- Open your
.cpp
file in VS Code. - Press
Ctrl+Shift+B
to build and run the program. - The program will execute with the specified input and output files.
- Create a new build system in Sublime Text (
Tools > Build System > New Build System
). - Name the file
your_name.sublime-build
and paste the following content:
{
"cmd": ["g++", "-Dchandan", "-Wextra", "-Wall", "-std=c++20", "$file", "-o", "$file_base_name.out"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "$file_path",
"selector": "source.cpp",
"variants": [
{
"name": "Run",
"cmd": ["bash", "-c", "g++ -Dchandan -Wextra -Wall -std=c++20 '$file' -o '$file_base_name.out' && './$file_base_name.out' < input.txt > output.txt"]
}
]
}
- Update
input.txt
andoutput.txt
in theyour_name.sublime-build
file to the names of your input and output files. - Replace
-Dchandan
with a custom macro name if needed.
- Open your
.cpp
file in Sublime Text. - Press
Ctrl+B
to build and run the program. - The program will execute with the specified input and output files.
-DDEBUG
is a preprocessor directive. You can change this to any name that suits your preference.- Ensure the
g++
compiler andgdb
debugger are installed on your Linux system.
Enjoy your seamless competitive programming setup!