Sublime Text3 配置C++(附oj刷题常用模板)

# 下载对应平台的sublime

sublime最新版下载, 字体样式个人喜欢Consolas, 另附注册码:

—– BEGIN LICENSE —–  
TwitterInc  
200 User License  
EA7E-890007  
1D77F72E 390CDD93 4DCBA022 FAF60790  
61AA12C0 A37081C5 D0316412 4584D136  
94D7F7D4 95BC8C1C 527DA828 560BB037  
D1EDDD8C AE7B379F 50C9D69D B35179EF  
2FE898C4 8E4277A8 555CE714 E1FB0E43  
D5D52613 C3D12E98 BC49967F 7652EED2  
9D2D2E61 67610860 6D338B72 5CF95C69  
E36B85CC 84991F19 7575D828 470A92AB  
—— END LICENSE ——

# Mac下配置

选择Tools > Build System > New Build System创建一个编译模板,名字命名为C++11

20170812150246958137367.png

文件内容如下:

{
    "cmd": ["g++", "${file}", "-o", "${file_path}/${file_base_name}"],
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.c, source.c++",

    "variants":
    [
        {
            "name": "Run",
            "cmd": ["bash", "-c", "g++ -std=c++11 '${file}' -o 'a' && open -a terminal '${file_path}/a'"]
        }
    ]
}

配置中的open -a terminal指的是从终端打开该文件, 如果不需要,可以将其去掉。
编写一个简单的c++程序测试一下
20170812150247043771743.png

Windows下配置

c++环境设置

  1. 在系统环境变量Path中添加MinGW > bin所在目录,
    点击下载MinGW
    20170814150272417980528.png

  2. 同样在Tools > Build System > New Build System新建编译模板,保存为C++11.sublime-build
    内容为:

C++.sublime-build

{   
  "encoding": "utf-8",  
  "working_dir": "$file_path",  
  "shell_cmd": "g++ -Wall \"$file_name\" -o \"$file_base_name\"",   
  "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",            
  "selector": "source.c++",     
  "variants":   
  [     
    {           
      "name": "Run",            
      "shell_cmd": "g++ -Wall  \"$file\" -o \"$file_base_name\" && start cmd /c \"\"${file_path}/${file_base_name}\" & pause\""     
    }   
  ]
}

# oj刷题常用模版

sublime中可以添加代码片段

创建方法:Tools (工具)> Developer > New Snippet(新片段)

1、在新建的文件中添加如下内容

<snippet>
    <content>
    <![CDATA[
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
const int inf = 0x3f3f3f3f;
#define LOCAL



int main(int argc, char * argv[]) 
{
    #ifdef LOCAL
    freopen("/Users/huangjiaming/Documents/Algorithm/oj/data.in", "r", stdin);
    //freopen("/Users/huangjiaming/Documents/Algorithm/oj/data.out", "w", stdout);
    #endif

    ${1:/* code */}

    while (~scanf("%d", ${2:/* var */}))
    {
    
    }

    return 0;
}]]>
    </content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <tabTrigger>acm</tabTrigger>
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <scope>source.c++</scope>
</snippet>

2、保存为acm.sublime-snippet
3、使用方法,在你的c++文件中输入acm关键字,再按下Tap键

效果如下

20170812150247176496944.gif

转载于:https://www.cnblogs.com/huangjiaming/p/7364004.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值