Do you want an IDE on which you just copy your test cases, run your code and see output on the same window?
Then Sublime text is for you, my friend.
We are going to set up sublime for Windows, Linux, and macOS.
Please follow the below steps for setting things up:
- Download Sublime Text from here: sublime
Download GCC compiler:
For Windows setup the C++ env from GFG article.
For Linux:
- Run on terminal:
sudo apt-get update sudo apt-get install build-essential sudo apt-get install manpages-dev
- To verify the installation run
gcc --version
, this should output which gcc version is installed.
- Run on terminal:
For macOS:
- Install GCC through homebrew by running
brew install gcc
. - Install gtimeout through homebrew by running
brew install coreutils
. - To verify the installation run
which gcc
, this should output the path where gcc is installed. - If you don't have homebrew install it from here homebrew
- Install GCC through homebrew by running
Let's Divide the window into three groups (one for c++ editor, one for input, and one for output).
- Create a directory with any name say C++ and open it in Sublime.
- Create three column from Layout:
- Join two blocks vertically:
- Save upper right as
input.in
file. - Save lower right as
output.in
file. - Save left column with a
cpp
file extension to compile c++ code.
Open sublime text and install PackageResourceViewer to add build for C++.
- Open Package Control.
- Choose Install Package.
- Install PackageResourceViewer by searching
PackageResourceViewer
PackageResourceViewer
Create a c++ build file with PackageResourceViewer:
- Open package control and search PackageResourceViewer: Open Resource.
- Click on C++.
- Open C++ Single File.sublime-build.
Change the content of build file for each OS distribution.
- For Windows:
{ "cmd" : ["g++ -std=c++14 $file_name -o $file_base_name && timeout 4s ./$file_base_name<input.in>output.in"], "selector" : "source.c", "shell": true, "working_dir" : "$file_path" }
- For Linux:
- Note I have g++-11 version at the time of writing. Please update the version which you have installed by checking with
g++ --version
{ "cmd" : ["g++-11 $file_name -o $file_base_name && gtimeout 4s ./$file_base_name<input.in>output.in"], "selector" : "source.c", "shell": true, "working_dir" : "$file_path" }
- Note I have g++-11 version at the time of writing. Please update the version which you have installed by checking with
- For macOS:
- Copy the path of GCC by running
which gcc
. - Edit the build file:
{ "cmd" : ["/usr/local/bin/g++-11 $file_name -o $file_base_name && gtimeout 4s ./$file_base_name<input.in>output.in"], "selector" : "source.c", "shell": true, "working_dir" : "$file_path" }
- Copy the path of GCC by running
- For Windows:
- Add your cpp code in c++ editor block and run program by
cmd + B
orctrl + B
.
Wola, Congratulations!!!!. Eat, Sleep, Code and Repeat.