1,安装编译器g++
下载地址:https://sourceforge.net/projects/mingw-w64/
装好mingw之后将bin/目录添加到path环境变量中去,然后再cmd中输入以下代码,测试是否装好
g++
如果出现下图所示情况,表明安装成功
2,在sublime中配置环境
tools > Build System > New Builed System
将其中的内容改成如下,并保存为CPP.sublime-build文件
{ //"shell_cmd": "make", "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++,source.cpp", "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"] }, {"name": "RunInShell", "shell_cmd": " start cmd /c ""${file_path}/${file_base_name}"&pause" " } ] }
然后Preferences > Key Bindings中输入以下内容
{"keys": ["f5"], "command": "build", "args": {"variant": "Run"}}, { "keys": ["f6"], "command": "build", "args": {"variant": "RunInCommand"} },
ctrl+n建立新文件,ctrl+s保存为.cpp文件,tools > Build System > CPP
写好之后f5或者f6编译运行程序
3,有用的插件
clang, EasyClangComplete、SublimeCodeIntel