Open In App

Setting up Sublime Text for C++ Competitive Programming Environment

Note: The following steps assume a Windows OS environment.

Sublime Text is a text editor for coding. It has a smooth user interface and other exciting features. During the live contest, it is always favorable to compile the program in a local IDE instead of an online IDE’s.



In this article, we will discuss how to set up a Sublime Text Editor for Competitive Programming in C++ how to create our own build system in the sublime text editor.

Install Sublime Text Editor:

Download the setup file of Sublime Text from here and then install it.



Install MinGW Compiler:

MinGW is a native Windows port of the GNU Compiler Collection (GCC), with freely distributable import libraries and header files for building native Windows applications.

Setting up the Environment

After completing the above steps, GCC is up and running. Now, the Environment Variable’s Path is to be updated. Follow the below steps for the same:  

Now Sublime Text is able to access g++ from its terminal as the path variable has been updated.

Creating a Build System

Sublime Text provides build systems to allow users to run external programs. Create a new build system for Sublime Text for setting up C++ compilation. 

{
    "cmd": ["g++.exe", "-std=c++17", "${file}",
            "-o", "${file_base_name}.exe",
            "&&", "${file_base_name}.exe<inputf.in>outputf.out"],
    "shell":true,
    "working_dir":"$file_path",
    "selector":"source.cpp"
}

The above block of code is used for taking input from the file “inputf.in” and prints the output to “outputf.out”.

Setting up the Window Layout

Create three new files as shown below and make sure all of them are in the same folder.

Now, perform the following steps:

Below is the image to illustrate the same:

Ready for executing the programs:

Precompile Headers:

The compilation time can speed up by precompiling all the header files i.e., by precompiling the bits/stdc++.h header file. Perform the following steps for doing so:

g++ stdc++.h -std=c++17

Article Tags :