How to Run C and C++ Program in Sublime Text



How to Run C and C++ Program in Sublime Text


In this tutorial you will learn how to run C and C++ program in sublime text on windows.
It is a very popular and widely used text editor by programmers and developers. Just follow below steps to configure sublime text to compile and run C and C++ programs. I have tested the steps in sublime text 3 but I am sure it will work for any other version also.

How to Run C and C++ Program in Sublime Text

Here I consider that you have installed GCC compiler on your system.

Part 1: Adding Path in Environment Variables

1. Copy the path of bin folder of GCC compiler. In my case the path looks like as shown below, it may be different in your case.
C:\Program Files (x86)\CodeBlocks\MinGW\bin
2. Now right click on Computer and select Properties. Then click on Advance system settings and after that click on Environment Variables.
3. In the next window under System variables find a variable with name Path. Select it and click on Edit button.
4. In Variable value text field go to end and then type semicolon and then paste the path of bin folder that you copied. See below screenshot.



5. Finally click on all OK buttons to save the settings.

Part 2: Configuring Sublime Text

Open sublime text and go to Tools > Build System > New Build System and then paste the following lines in it.
For C:

{
"shell_cmd" : "gcc $file_name -o ${file_base_name}",
"working_dir" : "$file_path",
"variants":
[
    {
        "name": "Run",
        "shell_cmd": "gcc $file_name -o ${file_base_name} && ${file_path}/${file_base_name}"
    }
]
}
Press ctrl+s and then save it with file name C_RUN.

For C++:

{
"shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\"",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",
"variants":
[
    {
        "name": "Run",
        "shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\""
    }
]

}
 
Press ctrl+s and then save it with file name CPP_RUN.

For running a program go to Tools > Build With and then select C_RUN – Run or CPP_RUN – Run according to the language you are using.



Comments

Post a Comment

Popular posts from this blog

Facts about being actuary !

জমির খতিয়ান কি কত প্রকার ও কি কি?