How to Run C/C++ in Sublime Text?

Habib Rahman
Geek Culture
Published in
3 min readJun 16, 2021

--

Learn to run C or CPP in Sublime Text, Lifesaver of Contest Programming

Christopher Gower Unsplash

C and C++ are the most powerful programming language in the world. Most of the super fast and complex libraries and algorithms are written in C or C++. Most powerful Kernel programs are also written in C. So, there is no way to skip it.

Most programmers prefer to write code in C or C++ in programming competitions. Tourist is considered the world's top programming contestant of all ages who write code in C++.

During programming competitions, programmers prefer to use a lightweight editor to focus on coding and algorithm design. Vim, Sublime Text, and Notepad++ are the most common editors. Apart from the competition, many software developers and professionals love to use Sublime Text because of its flexibility.

Gennady Korotkevich ( aka Tourist) — Belarusian Sport Programmer — Photo Wikipedia

I have discussed the steps we need to complete in this blog post before running a C/C++ code in Sublime Text. We will take the inputs from an input file and print outputs to an output file without using freopen file-related functions in C/C++.

Installing Sublime Text

  • For Windows, you can download it from the link.
  • For Ubuntu or Debian, we can install it as follows:

— Install the GPG key:

wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add -

— Now, we are selecting the stable channel to use:

echo "deb https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime-text.list

— Update, and install Sublime Text:

sudo apt-get update
sudo apt-get install sublime-text
  • For macOS, we can download it from this link.

JSON for Package New Build Package in Sublime Text

Our principal focus is to run our codes automatically, taking the inputs from a file without manually typing inputs every time we run our code.

So, we have to add a new build system. We have to go Tools > Build System > New Build System and then add the following code and save the file:

Finally, We can now build our code by pressing Command + B and see the outputs for the inputs of in.txt file into out.txt file.

Note: in.txt , out.txt And the source code should be in the same directory.

We can see the full video tutorial if we need to follow it step by step.

Conclusion

Thanks for your valuable time and for reading this article.

If you find this article helpful, please feel free to comment, share, and clap 👏 your hands. Please follow me on Medium for more posts like this. You can visit my web profile, read my blog posts, and follow me on Twitter.

You may check this article to learn the basics of web scraping and HTML Parsing.

--

--