代码一:
{
"cmd": ["g++", "${file}", "-std=c++11", "-o", "${file_path}\\\\${file_base_name}", "&", "start", "cmd", "/c", "${file_path}\\\\${file_base_name} & echo. & pause"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",
"shell": true,
"encoding":"utf-8",
"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"]
}
]
}
该代码实测可以运行project的,生成project.exe
但是build一个cpp文件时要注意sublime文件夹路径、cpp文件的文件路径均不能有空格
代码二:
{
// "shell_cmd": "make"
"encoding": "utf-8",
"working_dir": "$file_path",
"shell_cmd": "g++ -Wall -std=c++11 \"$file_name\" -o \"$file_base_name\"",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"selector": "source.cpp",
"variants":
[
{
"name": "Run",
"shell_cmd": "g++ -Wall -std=c++11 \"$file\" -o \"$file_base_name\" && \"${file_path}/${file_base_name}\""
},
{
"name": "RunInCmd",
"shell_cmd": "g++ -Wall -std=c++11 \"$file\" -o \"$file_base_name\" && start cmd /c \"\"${file_path}/${file_base_name}\" & echo. & pause \""
}
]
}
该代码实测可以运行一个cpp文件,生成filename.exe。用来写算法够用了。
参考并感谢:
https://blog.csdn.net/a19990412/article/details/82658981
https://www.cnblogs.com/whatiwhere/p/8664304.html
windows sublime text3 c++ 11环境配置注意事项