Configuration of Sublime text for C/C++
Sublime Text is cross-platform lightweight text editor. You can get latest version from Official Website.
Configuration for Linux
Taking input with Terminator
If you want to take input from stdio
you should have Terminator installed.
-
To configure for C for
c11
standard Open Sublime go to Tools -> Build System -> New Build System.and paste following Code. Change std to relevant version
{
"cmd": ["gcc", "-std=c11", "$file", "-o", "${file_path}/${file_base_name}.out"],
"file_regex": "^(..[^:]):([0-9]+):?([0-9]+)?:? (.)$",
"working_dir": "${file_path}",
"selector": "source.c",
"variants":
[
{
"name": "Run",
"cmd": ["bash", "-c", "gcc -std=c11 '${file}' -o '${file_path}/${file_base_name}.out' && terminator -x bash -c '\"${file_path}/${file_base_name}.out\" ; read'"]
}
]
}
- Similarly for C++ standard
c++14
paste following Code
{
"cmd": ["g++", "-std=c++14", "$file", "-o", "${file_path}/${file_base_name}.out"],
"file_regex": "^(..[^:]):([0-9]+):?([0-9]+)?:? (.)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++, source.cxx, source.cpp",
"variants":
[
{
"name": "Run",
"cmd": ["bash", "-c", "g++ -std=c++14 '${file}' -o '${file_path}/${file_base_name}.out' && terminator -x bash -c '\"${file_path}/${file_base_name}.out\" ; read'"]
}
]
}
Configuration for Windows
If you don’t have C/C++ compiler installed. Install TDM-GCC compiler.
- To configure for
C++17
in windows. Open Sublime go to Tools -> Build System -> New Build System.
{
"cmd": ["g++.exe", "-std=c++17", "${file}",
"-o", "${file_base_name}.exe",
"&&", "${file_base_name}.exe<input.txt >output.txt"],
"shell":true,
"working_dir":"$file_path",
"selector":"source.cpp"
}
-
For
C11
use{ "cmd": ["gcc.exe", "-std=c11", "${file}", "-o", "${file_base_name}.exe", "&&", "${file_base_name}.exe<input.txt >output.txt"], "shell":true, "working_dir":"$file_path", "selector":"source.c" }
I am attaching Some links for reference