Sublime Text 2 Run built file after building - c++

So I'm new to this but I am using Sublime Text 2 on Mac OS X and the problem is that when i simply run my c++ code it runs in a local output tab and it dont allow me to do any input, so to input variables i need to build my code and then locate it in finder and open in terminal, but is there a way to allow input in that little output windows or simply tell ST2 to open the built file just after building it?
P.S.
I found the answear to my own question :D
I will add it so if someone needs it - it will be here.
so you need to eddit c++.sublime-build file - just add this
"cmd": ["bash", "-c", "g++ '${file}' -o '${file_path}/${file_base_name}' && open -a Terminal.app '${file_path}/${file_base_name}'"]
before
"variants":
and the when you build your programm it will just open it in terminal

Related

Beginner Coder - Interact with Build Window in Sublime Text [duplicate]

I'm trying to get Sublime Text 3 to run a Python script. A simple two liner
var = raw_input("Enter something: ")
print("You entered " + var)
which asks for input, waits for it, then prints it out in windows console prompt.
Seeing the number of similar questions on the site, this is a problem for quite a number of users, so I went through those and tried ... stuff. Made a copy of exec.py file, commented that one line, made a new pythonw build file, tried messing about with the build file ... nothing seems to work.
In lack of a definite solution, how do you work with input using Sublime Text?
Sublime Text on its own cannot handle input via raw_input() (Python 2) or input() (Python 3). The same is true of other languages as well - Ruby's gets, Java's Scanner class, Node's readline class, scanf in C, cin in C++, etc. One short-term solution is to get Package Control if you don't already have it, then install SublimeREPL. It allows you to transfer or run part or all of your code through the running REPL. It may require some configuration of the Main.sublime-menu files to get your preferred interpreter to run properly. Alternatively, you can use the excellent Terminus plugin - details are at the bottom.
If the code you're running doesn't play well with SublimeREPL (for instance, you're using C/C++/Java/etc. and need to compile code before it runs), or you just want to run it independently of Sublime, you'll need to make your own build system. Save the following as Packages/User/Python_cmd.sublime-build:
Windows
{
"cmd": ["start", "cmd", "/k", "c:/python38/python.exe", "$file"],
"selector": "source.python",
"shell": true,
"working_dir": "$file_dir",
"env": {"PYTHONIOENCODING": "utf-8"}
}
changing the path to your Python executable as appropriate. Then, go to Tools -> Build System and select Python_cmd, and when you hit CtrlB to build, a new cmd window will open up with your file running. The /k option returns to the command prompt, without closing the window, after your program is done running so you can examine output, tracebacks, etc.
Please note that this build system is Windows-specific, as macOS and Linux do not have cmd. Build systems for those platforms are below.
macOS
If you are running OS X/macOS, the following build system will open your program in a new instance of Terminal. Save it as Packages/User/Python_Terminal.sublime-build. In my testing on macOS 10.15, the Terminal window didn't always come to the top when activated, so if you may need to look for it behind other windows.
{
"shell_cmd": "osascript -e 'tell app \"Terminal\" to do script \"cd $file_path && python3 -u $file\"'",
"working_dir": "$file_path",
"selector": "source.python",
"env": {"PYTHONIOENCODING": "utf-8"}
}
You may need to specify the path to your Python executable if it's not on your $PATH.
Linux
And finally, here is a build system for Linux. It was tested on Ubuntu, so if you use another distribution you'll need to ensure that gnome-terminal is installed. Save it as Packages/User/Python_shell.sublime-build. Once the program has finished running, hit any key to close the window.
{
"shell_cmd": "gnome-terminal --working-directory=$file_path -- bash -c 'python3 -u \"$file\" && read -n 1 -s -r'",
"working_dir": "$file_path",
"selector": "source.python",
"env": {"PYTHONIOENCODING": "utf-8"}
}
For reference, the Packages directory is the one opened when selecting Preferences → Browse Packages…:
Linux: ~/.config/sublime-text-3/Packages or ~/.config/sublime-text/Packages
OS X: ~/Library/Application Support/Sublime Text 3/Packages or ~/Library/Application Support/Sublime Text/Packages
Windows Regular Install: C:\Users\YourUserName\AppData\Roaming\Sublime Text 3\Packages or C:\Users\YourUserName\AppData\Roaming\Sublime Text\Packages
Windows Portable Install: InstallationFolder\Sublime Text 3\Data\Packages InstallationFolder\Sublime Text\Data\Packages
The exact path depends on version and whether or not you upgraded from Sublime Text 3.
I have only tested these build systems with Python, but they should work fine for any language. When modifying, just make sure that all the single and double quotes match up – you'll get errors or unexpected behavior if they don't.
UPDATE
There is a platform-independent plugin called Terminus that, among other things, provides a drop-in replacement for the default exec build system engine. It allows you to interact with your program in the build panel below your code. Once you've installed it from Package Control, create the following build system (again, for Python):
{
"target": "terminus_exec",
"cancel": "terminus_cancel_build",
"cmd": [
"/path/to/python", "-u", "$file"
],
"working_dir": "$file_path",
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
}
You'll need to adjust the path to your Python executable, as above. Make sure you read the documentation to find out all the other ways you can make use of this great plugin.
To add on to the answer from Shritam Kumar Mund, to make a key binding for this:
{ "keys": ["alt+k", "alt+k"], "command": "repl_open", "args": {"cmd":
["python", "-u", "$file_basename"], "cwd": "$file_path", "encoding":
"utf8", "extend_env": {"PYTHONIOENCODING": "utf-8"}, "external_id":
"python", "syntax": "Packages/Python/Python.tmLanguage", "type":
"subprocess"}},
I found this by using the following in the console:
sublime.log_commands(True)
Sublime Text does not support inputting data into a program. For working with inputs you need to install a package called SublimeREPL.
Follow this:
open Sublime Text >> CTRL + P
CTRL + P will open the Package control
Click on Package Control: Install package
Wait for a sec to pop up a search bar.
Type SublimeREPL and Click it.
It'll get installed in a few secs.
Then follow the following steps to run your program;
Tools >> SublimeREPL >> Python >> Python run Current File
It'll open a new window, where you can give your input and get the output.
You can use this sublime_build file which make run on cmd when you press ctrl+B .
Just go to tool ->sublime build->new build system and paste the below given as it is;
I have personally edited this sublime build file with my experience and believe me it has some good functionalities:
color changing when program terminates or ends
interactive output and input
console window automatic opening
pause after program finishes and wait till enter
{
"cmd":["start", "cmd", "/c" ,"python $file && color b0 && pause"],
"selector": "source.python",
"working_dir": "${file_path}",
"file_regex": "(.+):(\\d+): error: ",
"shell": true
}
Thanks #MattDMo for the answer, which doesn't require installing any plugin. But after I tried the command in macOS:
"shell_cmd": "osascript -e 'tell app \"Terminal\" to do script \"cd $file_path && python3 -u $file\"'",
I find it seems to run from background every time, which is not convenient.
So I tried another method: to use a temp.sh to run. Here is the command:
"cmd": ["zsh", "-c", "echo \"python3 ${file}\" > /tmp/tmp.sh ; chmod +x /tmp/tmp.sh ; open -a Terminal /tmp/tmp.sh ; sleep 2 ;rm /tmp/tmp.sh"],
This method will pop up a new window to the front, and it should be feasible on other platforms after a small modification, but I didn't try.
here is the full content in "python_input.sublime-build":
{
"cmd": ["zsh", "-c", "echo \"python3 ${file}\" > /tmp/tmp.sh ; chmod +x /tmp/tmp.sh ; open -a Terminal /tmp/tmp.sh ; sleep 2 ;rm /tmp/tmp.sh"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.python",
"env": {"PYTHONIOENCODING": "utf-8"},
}

Not able read from input output files in Sublime Text 3

I have successfully installed MinGW and have tried running cpp programs from command prompt and it runs perfectly. In Sublime I tried using default build system 'C++ Single File', it prints simple statements in the console below but it cannot take input. After building the programs with 'cin' commands the program does not show any output and I try giving input in the console below and press ENTER but nothing happens. Then I found a method of using 'freopen' command to take input from a file and output to a different file. But the programs runs successfully but doesn't output anything in the output file. Same problem -- mingw64 + sublime 3 input output files not working
After this I tried many other build files I found on web but none of them work.
{
"cmd": ["g++.exe", "-std=c++17", "${file}",
"-o", "${file_base_name}.exe",
"&&", "${file_base_name}.exe<input.in>output.out"],
"shell":true,
"working_dir":"$file_path",
"selector":"source.cpp"
}
The output.out file is always empty. I have input and output files in same directly and I think it is reading input correctly because when I delete the input file it gives an error that it cannot find the input file. I even tried using text files (input.txt, output.txt) after moding build system code but it doesn't work.
I have many other build codes but none of them works.
I tried running g++.exe -std=c++17 contest1a.cpp -o contest1a.exe && contest1a.exe<input.in>output.out in command prompt but the output.out file is still empty.
I replaced first line with "cmd" : ["g++ -std=c++14 $file_name -o $file_base_name && timeout 4s $file_base_name < input.in > output.out"], but it gives error because I think .exe is not suffixed which I tried adding and program runs but output is still empty.
Why is 'freopen' not working, why is any build not able to write in output file ?
So it turns out Windows defender has a new feature 'Block Folder Access' which blocked my program from modifying the output file. I wasted one day solving this issue smh

How to open a .exe window for CPP files in Sublime Text 3? [duplicate]

I'm trying to get Sublime Text 3 to run a Python script. A simple two liner
var = raw_input("Enter something: ")
print("You entered " + var)
which asks for input, waits for it, then prints it out in windows console prompt.
Seeing the number of similar questions on the site, this is a problem for quite a number of users, so I went through those and tried ... stuff. Made a copy of exec.py file, commented that one line, made a new pythonw build file, tried messing about with the build file ... nothing seems to work.
In lack of a definite solution, how do you work with input using Sublime Text?
Sublime Text on its own cannot handle input via raw_input() (Python 2) or input() (Python 3). The same is true of other languages as well - Ruby's gets, Java's Scanner class, Node's readline class, scanf in C, cin in C++, etc. One short-term solution is to get Package Control if you don't already have it, then install SublimeREPL. It allows you to transfer or run part or all of your code through the running REPL. It may require some configuration of the Main.sublime-menu files to get your preferred interpreter to run properly. Alternatively, you can use the excellent Terminus plugin - details are at the bottom.
If the code you're running doesn't play well with SublimeREPL (for instance, you're using C/C++/Java/etc. and need to compile code before it runs), or you just want to run it independently of Sublime, you'll need to make your own build system. Save the following as Packages/User/Python_cmd.sublime-build:
Windows
{
"cmd": ["start", "cmd", "/k", "c:/python38/python.exe", "$file"],
"selector": "source.python",
"shell": true,
"working_dir": "$file_dir",
"env": {"PYTHONIOENCODING": "utf-8"}
}
changing the path to your Python executable as appropriate. Then, go to Tools -> Build System and select Python_cmd, and when you hit CtrlB to build, a new cmd window will open up with your file running. The /k option returns to the command prompt, without closing the window, after your program is done running so you can examine output, tracebacks, etc.
Please note that this build system is Windows-specific, as macOS and Linux do not have cmd. Build systems for those platforms are below.
macOS
If you are running OS X/macOS, the following build system will open your program in a new instance of Terminal. Save it as Packages/User/Python_Terminal.sublime-build. In my testing on macOS 10.15, the Terminal window didn't always come to the top when activated, so if you may need to look for it behind other windows.
{
"shell_cmd": "osascript -e 'tell app \"Terminal\" to do script \"cd $file_path && python3 -u $file\"'",
"working_dir": "$file_path",
"selector": "source.python",
"env": {"PYTHONIOENCODING": "utf-8"}
}
You may need to specify the path to your Python executable if it's not on your $PATH.
Linux
And finally, here is a build system for Linux. It was tested on Ubuntu, so if you use another distribution you'll need to ensure that gnome-terminal is installed. Save it as Packages/User/Python_shell.sublime-build. Once the program has finished running, hit any key to close the window.
{
"shell_cmd": "gnome-terminal --working-directory=$file_path -- bash -c 'python3 -u \"$file\" && read -n 1 -s -r'",
"working_dir": "$file_path",
"selector": "source.python",
"env": {"PYTHONIOENCODING": "utf-8"}
}
For reference, the Packages directory is the one opened when selecting Preferences → Browse Packages…:
Linux: ~/.config/sublime-text-3/Packages or ~/.config/sublime-text/Packages
OS X: ~/Library/Application Support/Sublime Text 3/Packages or ~/Library/Application Support/Sublime Text/Packages
Windows Regular Install: C:\Users\YourUserName\AppData\Roaming\Sublime Text 3\Packages or C:\Users\YourUserName\AppData\Roaming\Sublime Text\Packages
Windows Portable Install: InstallationFolder\Sublime Text 3\Data\Packages InstallationFolder\Sublime Text\Data\Packages
The exact path depends on version and whether or not you upgraded from Sublime Text 3.
I have only tested these build systems with Python, but they should work fine for any language. When modifying, just make sure that all the single and double quotes match up – you'll get errors or unexpected behavior if they don't.
UPDATE
There is a platform-independent plugin called Terminus that, among other things, provides a drop-in replacement for the default exec build system engine. It allows you to interact with your program in the build panel below your code. Once you've installed it from Package Control, create the following build system (again, for Python):
{
"target": "terminus_exec",
"cancel": "terminus_cancel_build",
"cmd": [
"/path/to/python", "-u", "$file"
],
"working_dir": "$file_path",
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
}
You'll need to adjust the path to your Python executable, as above. Make sure you read the documentation to find out all the other ways you can make use of this great plugin.
To add on to the answer from Shritam Kumar Mund, to make a key binding for this:
{ "keys": ["alt+k", "alt+k"], "command": "repl_open", "args": {"cmd":
["python", "-u", "$file_basename"], "cwd": "$file_path", "encoding":
"utf8", "extend_env": {"PYTHONIOENCODING": "utf-8"}, "external_id":
"python", "syntax": "Packages/Python/Python.tmLanguage", "type":
"subprocess"}},
I found this by using the following in the console:
sublime.log_commands(True)
Sublime Text does not support inputting data into a program. For working with inputs you need to install a package called SublimeREPL.
Follow this:
open Sublime Text >> CTRL + P
CTRL + P will open the Package control
Click on Package Control: Install package
Wait for a sec to pop up a search bar.
Type SublimeREPL and Click it.
It'll get installed in a few secs.
Then follow the following steps to run your program;
Tools >> SublimeREPL >> Python >> Python run Current File
It'll open a new window, where you can give your input and get the output.
You can use this sublime_build file which make run on cmd when you press ctrl+B .
Just go to tool ->sublime build->new build system and paste the below given as it is;
I have personally edited this sublime build file with my experience and believe me it has some good functionalities:
color changing when program terminates or ends
interactive output and input
console window automatic opening
pause after program finishes and wait till enter
{
"cmd":["start", "cmd", "/c" ,"python $file && color b0 && pause"],
"selector": "source.python",
"working_dir": "${file_path}",
"file_regex": "(.+):(\\d+): error: ",
"shell": true
}
Thanks #MattDMo for the answer, which doesn't require installing any plugin. But after I tried the command in macOS:
"shell_cmd": "osascript -e 'tell app \"Terminal\" to do script \"cd $file_path && python3 -u $file\"'",
I find it seems to run from background every time, which is not convenient.
So I tried another method: to use a temp.sh to run. Here is the command:
"cmd": ["zsh", "-c", "echo \"python3 ${file}\" > /tmp/tmp.sh ; chmod +x /tmp/tmp.sh ; open -a Terminal /tmp/tmp.sh ; sleep 2 ;rm /tmp/tmp.sh"],
This method will pop up a new window to the front, and it should be feasible on other platforms after a small modification, but I didn't try.
here is the full content in "python_input.sublime-build":
{
"cmd": ["zsh", "-c", "echo \"python3 ${file}\" > /tmp/tmp.sh ; chmod +x /tmp/tmp.sh ; open -a Terminal /tmp/tmp.sh ; sleep 2 ;rm /tmp/tmp.sh"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.python",
"env": {"PYTHONIOENCODING": "utf-8"},
}

How to run code after cin in Sublime Text 3 [duplicate]

I'm trying to get Sublime Text 3 to run a Python script. A simple two liner
var = raw_input("Enter something: ")
print("You entered " + var)
which asks for input, waits for it, then prints it out in windows console prompt.
Seeing the number of similar questions on the site, this is a problem for quite a number of users, so I went through those and tried ... stuff. Made a copy of exec.py file, commented that one line, made a new pythonw build file, tried messing about with the build file ... nothing seems to work.
In lack of a definite solution, how do you work with input using Sublime Text?
Sublime Text on its own cannot handle input via raw_input() (Python 2) or input() (Python 3). The same is true of other languages as well - Ruby's gets, Java's Scanner class, Node's readline class, scanf in C, cin in C++, etc. One short-term solution is to get Package Control if you don't already have it, then install SublimeREPL. It allows you to transfer or run part or all of your code through the running REPL. It may require some configuration of the Main.sublime-menu files to get your preferred interpreter to run properly. Alternatively, you can use the excellent Terminus plugin - details are at the bottom.
If the code you're running doesn't play well with SublimeREPL (for instance, you're using C/C++/Java/etc. and need to compile code before it runs), or you just want to run it independently of Sublime, you'll need to make your own build system. Save the following as Packages/User/Python_cmd.sublime-build:
Windows
{
"cmd": ["start", "cmd", "/k", "c:/python38/python.exe", "$file"],
"selector": "source.python",
"shell": true,
"working_dir": "$file_dir",
"env": {"PYTHONIOENCODING": "utf-8"}
}
changing the path to your Python executable as appropriate. Then, go to Tools -> Build System and select Python_cmd, and when you hit CtrlB to build, a new cmd window will open up with your file running. The /k option returns to the command prompt, without closing the window, after your program is done running so you can examine output, tracebacks, etc.
Please note that this build system is Windows-specific, as macOS and Linux do not have cmd. Build systems for those platforms are below.
macOS
If you are running OS X/macOS, the following build system will open your program in a new instance of Terminal. Save it as Packages/User/Python_Terminal.sublime-build. In my testing on macOS 10.15, the Terminal window didn't always come to the top when activated, so if you may need to look for it behind other windows.
{
"shell_cmd": "osascript -e 'tell app \"Terminal\" to do script \"cd $file_path && python3 -u $file\"'",
"working_dir": "$file_path",
"selector": "source.python",
"env": {"PYTHONIOENCODING": "utf-8"}
}
You may need to specify the path to your Python executable if it's not on your $PATH.
Linux
And finally, here is a build system for Linux. It was tested on Ubuntu, so if you use another distribution you'll need to ensure that gnome-terminal is installed. Save it as Packages/User/Python_shell.sublime-build. Once the program has finished running, hit any key to close the window.
{
"shell_cmd": "gnome-terminal --working-directory=$file_path -- bash -c 'python3 -u \"$file\" && read -n 1 -s -r'",
"working_dir": "$file_path",
"selector": "source.python",
"env": {"PYTHONIOENCODING": "utf-8"}
}
For reference, the Packages directory is the one opened when selecting Preferences → Browse Packages…:
Linux: ~/.config/sublime-text-3/Packages or ~/.config/sublime-text/Packages
OS X: ~/Library/Application Support/Sublime Text 3/Packages or ~/Library/Application Support/Sublime Text/Packages
Windows Regular Install: C:\Users\YourUserName\AppData\Roaming\Sublime Text 3\Packages or C:\Users\YourUserName\AppData\Roaming\Sublime Text\Packages
Windows Portable Install: InstallationFolder\Sublime Text 3\Data\Packages InstallationFolder\Sublime Text\Data\Packages
The exact path depends on version and whether or not you upgraded from Sublime Text 3.
I have only tested these build systems with Python, but they should work fine for any language. When modifying, just make sure that all the single and double quotes match up – you'll get errors or unexpected behavior if they don't.
UPDATE
There is a platform-independent plugin called Terminus that, among other things, provides a drop-in replacement for the default exec build system engine. It allows you to interact with your program in the build panel below your code. Once you've installed it from Package Control, create the following build system (again, for Python):
{
"target": "terminus_exec",
"cancel": "terminus_cancel_build",
"cmd": [
"/path/to/python", "-u", "$file"
],
"working_dir": "$file_path",
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
}
You'll need to adjust the path to your Python executable, as above. Make sure you read the documentation to find out all the other ways you can make use of this great plugin.
To add on to the answer from Shritam Kumar Mund, to make a key binding for this:
{ "keys": ["alt+k", "alt+k"], "command": "repl_open", "args": {"cmd":
["python", "-u", "$file_basename"], "cwd": "$file_path", "encoding":
"utf8", "extend_env": {"PYTHONIOENCODING": "utf-8"}, "external_id":
"python", "syntax": "Packages/Python/Python.tmLanguage", "type":
"subprocess"}},
I found this by using the following in the console:
sublime.log_commands(True)
Sublime Text does not support inputting data into a program. For working with inputs you need to install a package called SublimeREPL.
Follow this:
open Sublime Text >> CTRL + P
CTRL + P will open the Package control
Click on Package Control: Install package
Wait for a sec to pop up a search bar.
Type SublimeREPL and Click it.
It'll get installed in a few secs.
Then follow the following steps to run your program;
Tools >> SublimeREPL >> Python >> Python run Current File
It'll open a new window, where you can give your input and get the output.
You can use this sublime_build file which make run on cmd when you press ctrl+B .
Just go to tool ->sublime build->new build system and paste the below given as it is;
I have personally edited this sublime build file with my experience and believe me it has some good functionalities:
color changing when program terminates or ends
interactive output and input
console window automatic opening
pause after program finishes and wait till enter
{
"cmd":["start", "cmd", "/c" ,"python $file && color b0 && pause"],
"selector": "source.python",
"working_dir": "${file_path}",
"file_regex": "(.+):(\\d+): error: ",
"shell": true
}
Thanks #MattDMo for the answer, which doesn't require installing any plugin. But after I tried the command in macOS:
"shell_cmd": "osascript -e 'tell app \"Terminal\" to do script \"cd $file_path && python3 -u $file\"'",
I find it seems to run from background every time, which is not convenient.
So I tried another method: to use a temp.sh to run. Here is the command:
"cmd": ["zsh", "-c", "echo \"python3 ${file}\" > /tmp/tmp.sh ; chmod +x /tmp/tmp.sh ; open -a Terminal /tmp/tmp.sh ; sleep 2 ;rm /tmp/tmp.sh"],
This method will pop up a new window to the front, and it should be feasible on other platforms after a small modification, but I didn't try.
here is the full content in "python_input.sublime-build":
{
"cmd": ["zsh", "-c", "echo \"python3 ${file}\" > /tmp/tmp.sh ; chmod +x /tmp/tmp.sh ; open -a Terminal /tmp/tmp.sh ; sleep 2 ;rm /tmp/tmp.sh"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.python",
"env": {"PYTHONIOENCODING": "utf-8"},
}

How to compile and run c++ programs with sublime text 3?

I want to compile and run a c++ program in cmd every time I hit CTRL+B in Sublime Text 3. Also I need to keep the window alive after the program is fully executed. I particularly love the build system which code-block uses. Can I implement the same system in Sublime?
So far, I have following build system:
{
"cmd": ["mingw32-g++", "-o", "$file_base_name", "$file"],
"path": "C:\\MinGW\\bin\\",
"variants": [
{
"cmd": ["start", "cmd", "/k", "$file_base_name"],
"shell": true,
"name": "Run"
}
]
}
The only problem here is that I have to compile first and then run it. I want to have it compiled and run in a single operation.
Edit:
I have solved this problem by the following build system:
{
"cmd": ["g++.exe", "-std=c++11", "-o", "$file_base_name", "$file", "&&", "start", "cmd", "/c", "$file_base_name & echo. & echo. & pause"],
"shell": true,
"selector": "source.c++"
}
Sublime Text is a text editor wherein you can use different languages under the same hood.
Regarding your c++ program you have to install some packages for the version of c++ you are using. I recommend to watch some tutorials to get a step by step procedure and better understanding.
{
"shell_cmd": "g++ -std=c++11 -Wall \"${file}\" -o \"${file_path}/${file_base_name}\" && start cmd /k \"$file_base_name\"",
"working_dir": "${file_path}",
"selector": "source.cpp, source.cxx, source.cc, source.c++"
}
go to Tools -> build system -> new build system -> Paste It -> save it as "C++", then close it.
now save your C++/C code with .cpp extention (important .c extention is not supported) then to compile it go to tools -> build with Select "C++"
file download link:https://github.com/mahirx/configurations/blob/master/sublime_text/c_and_c%2B%2Bv2/C%2B%2B.sublime-build
please notify me if you found any mistakes.
Configure your editor to run make (or ninja ...) for CTRL B and use a Makefile, a build.ninja, or some other build automation tool. So you could add the appropriate rule (to your Makefile etc....) to run something else.
(both GNU make and ninja have good documentation and tutorials, and you could ask questions about them on SO, with some MCVE)
Source code editors are tools to edit source code. Configure them to run the external programs (compilers, debuggers, your own thing, ... or make or ninja) appropriately.
The only problem here is that I have to compile first and then run it. I want to have it compiled and run in a single operation.
So build with a good enough build automation tool. Configure your editor to run make, and edit your Makefile to make "compile then run" the default target (and likewise with ninja and its build.ninja file). Remember that compilers like GCC (even started from IDEs) are command line programs (and your mingw32-g++ is a GCC compiler).
Take also the good habit to compile with all warnings and debug info, so pass -Wall -Wextra -g to your GCC that is your mingw32-g++ (hence, edit appropriately your Makefile or build.ninja file).
In other words, an IDE - that is just a buzzword - is a source code editor suitably configured to run other programs. My preference is emacs