How to compile and run C/C++ code from "Sublime Text 2" editor?

I use ST2 for writing C/C++ code during competitions, but I have to use CodeBlocks for compiling and running the code. Is there any way to compile and run code within the ST2. I have googled for this problem and found this blog this technique is working but this require your .cpp or .c files to be placed inside a particular directory but I don’t want this. help me plz.

1 Like

For ubuntu u can use this…LINK!!!


I use Ubuntu, and this works nicely for me-

To compile and run the executable simply use Shift+Ctrl+B shortcut or from “Tools” menu you can select option “Run”.

However I am unable to input text to executable. The solution is simple, include this at top inside main()

    freopen("in.txt", "r", stdin);

in.txt should be in same directory as code, and contains all the input.

However @kunal361’s suggestion for using terminal is much better and powerful.


what for windows, do we have to follow same procedure?