Setting Up Sublime Text and Your C++ compiler
- In Sublime Text, execute the New Snippet command from the Tools menu.
- Replace the text in the new snippet with the following text
<snippet>
<content><![CDATA[
#include <QCoreApplication>
#include <QTextStream>
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
${1:QTextStream cin(stdin);}
${2:QTextStream cout(stdout);}
$0
return app.exec();
}
]]></content>
<tabTrigger>qt</tabTrigger>
</snippet>
- Select Save As from the file menu. Sublime should open a file dialog in its Packages folder.
- Under the Packages folder, create a new subfolder named cupp.sublime-package.
- In the new cupp.sublime-package folder, save the snippet as qt.sublime-snippet.
- You should now be able to open a new file, type qt followed by TAB to start a qt project.
- Next, from Sublime select Tools → Build System → New Build System.
- On a Mac, replace the text in the new build system with the following text.
{
"shell_cmd": "g++ $file;./a.out",
"working_dir": "$file_path"
}
- On a PC, add the directory of your compiler to the PATH via the Control Panel, then replace the text in the new build system with the following text.
{
"shell_cmd": "g++ $file && a.exe"
"working_dir": "$file_path"
}
for MinGW, or
{
"shell_cmd": "vcvars32.bat && cl $file && $file_base_name.exe",
"working_dir": "$file_path"
}
for Visual Studio.
- Save the build system as gcc.sublime-build in the cupp.sublime-package folder created above.
- In Sublime, select Tools->Build Systems->gcc.
- Henceforth, you may compile and run your program using Ctrl + B.