轻巧便捷的sublime text 3代码编辑功能非常强大,不过作为一款代码编辑软件,我们要是让它能把我们的c或者c++代码run起来,变成一个轻量级编译器那就更好了!今天来给大家说一下怎么在sublime下配置c/c++,使它能run C和C++的代码 (附Sublime下载地址:Sublime Text 3))[http://www.sublimetext.com/]
首先,我们要有一个编译器,如果你已经有了CodeBlocks或者Dev-C++,那么直接看下一步就好了。如果没有的话,我们需要先下载一个编译器,这里是 (MinGW的下载地址:MinGW)[http://www.mingw.org/]
安装mingw
配置环境变量。找到你的MinGW安装路径下的bin文件夹,配置环境变量
配置sublime,打开sublime,点击Tools→Build System→New Build System
{
"cmd": ["g++", ,"-Wall","${file}", "-o", "${file_path}/${file_base_name}"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",
"encoding":"cp936",
"variants":
[
{
"name": "Run",
"cmd": ["cmd", "/c", "g++", "-Wall","${file}", "-o", "${file_path}/${file_base_name}", "&&", "cmd", "/c", "${file_path}/${file_base_name}"]
},
{
"name": "RunInCommand",
"cmd": ["cmd", "/c", "g++", "-Wall","${file}", "-o", "${file_path}/${file_base_name}", "&&", "start", "cmd", "/c", "${file_path}/${file_base_name} & echo.&pause"]
}
]
}
配置编译快捷键
[
{"keys": ["ctrl+F11"], "command": "build", "args": {"variant": "RunInCommand"}}
]