您的位置:首页 > 编程语言 > C语言/C++

Sublime Text 3 设置C/C++编译环境

2016-07-19 19:32 696 查看
虽然sublime自带一个C语言的编译功能,但却无法使用,需要一定的配置才可以运行。

安装MinGW

要想编译C语言首先要有编译器,Windows平台主要是
gcc
g++
,是通过安装MinGW实现的。

MinGW的官网是 http://www.mingw.org/ ,但是从官网安装很麻烦,在线安装经常龟速容易失败。

博主推荐的方法是借助codeblocks,选择带有MinGW的版本安装(100M以上)。

博主也提供一个 codeblocks-16.01mingw-setup 的百度云下载,感觉codeblocks官网还是下载慢。

安装后把MinGW文件夹复制出来放到C盘根目录就可以了。

环境变量配置

右键计算机->属性->高级系统设置->环境变量



C:\MinGW\bin
添加到path变量中,注意前后英文分号。



Build System 配置

Tools -> Build System -> New Build System



将下面代码粘贴,并保存为
gcc.sublime-build


{
"encoding": "cp936",
"working_dir": "$file_path",
"shell_cmd": "g++ -Wall -std=c++0x -fexec-charset=GBK $file_name -o $file_base_name",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"selector": "source.c++",

"variants":
[
{
"name": "Run",
"shell_cmd": "g++ -Wall -fexec-charset=utf-8 \"$file\" -o \"$file_base_name\" && start cmd /c \"\"${file_path}/${file_base_name}\" & pause\""
}
]
}


这样就可以用cmd运行,并且scanf也能读取。

模板配置

sublime我认为最方便的地方就是可以设置一些模板,比如博主参加ACM竞赛开头会有很多在每道题都出现的语句,头文件等,如果有模板就会非常方便。

<snippet>
<content><![CDATA[
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <map>
#include <stack>
#include <queue>
#define LL long long
#define INF 0x3f3f3f3

using namespace std;

const double eps = 1e-8;
const int MAXN = (int)1e5 + 5;
const LL MOD = 1000000007;

int main()
{
#ifndef ONLINE_JUDGE
//freopen("in.txt", "r", stdin);
#endif

int cas;
scanf("%d", &cas);
while(cas--)
{
${1}
}
return 0;
}
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<!-- <tabTrigger>hello</tabTrigger> -->
<tabTrigger>acm</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->
<scope>source.c++</scope>
</snippet>


中间代码的位置当然可以修改。然后保存为
文件名.sublime-snippet
。例如博主起名为
acm.sublime-snippet
,之后只要用sublime打开
.cpp
文件,输入
acm
-> 回车就可以显示中间代码。是不是很方便啊~

演示效果如下:



推荐插件

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  sublime c语言