之前在网上找了很多配置教程都没成功,要么只能编译,要么只能运行编译好后的exe,没办法一键运行。
方法:
- 操作方式: 点击**
工具
,再选编译系统
,再选新建编译系统
** - 然后,把下面的代码,全部复制,并且,替换掉原来的那些地方。
- 之后保存就好了。 比如说,我保存的文件名就是
CPP.sublime-build
运行代码(改编自https://blog.csdn.net/a19990412/article/details/82658981,编译是可以的,但是运行有点问题,已修改):
{ "cmd": ["g++", "${file}", "-std=c++11", "-o", "${file_path}\\${file_base_name}", "&", "start", "cmd", "/c", "${file_base_name}.exe & echo. & pause"], "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$", "working_dir": "${file_path}", "selector": "source.c, source.c++", "shell": true, "encoding":"cp936", "variants": [ { "name" : "Build Only", "cmd":["g++", "${file}", "-std=c++11", "-o", "${file_path}\\${file_base_name}"] }, { "name" : "Run Only", "cmd" : ["start", "cmd", "/c", "${file_path}\\${file_base_name} & echo. & pause"] }, { "name" : "Pipe Build and Run", "cmd":["g++", "${file}", "-std=c++11", "-o", "${file_path}\\${file_base_name}","&","${file_path}\\${file_base_name}", "<","${file_path}\\in",">","${file_path}\\out"] }, { "name" : "Pipe Run Only", "cmd" : ["${file_base_name}", "<","in",">","out"] }, { "name" : "Project Build & Run", "cmd" : ["g++", "${file_path}\\*.cpp", "-std=c++11", "-o", "${file_path}\\project", "&", "start", "cmd", "/c", "${file_path}\\project & echo. & pause"] }, { "name" : "Project Build Only", "cmd" : ["g++", "${file_path}\\*.cpp", "-std=c++11", "-o", "${file_path}\\project"] }, { "name" : "Project Run Only", "cmd" : ["start", "cmd", "/c", "${file_path}\\project & echo. & pause"] } ] }
然后重启软件,在工具选项里选择 用……编译
选择你刚刚的文件名即可