将Sublime Text 3中的程序编译为c ++ 14作为默认值 [英] Compiling program as c++ 14 in Sublime Text 3 as default

查看:134
本文介绍了将Sublime Text 3中的程序编译为c ++ 14作为默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我们可以编译程序为C ++使用g ++编译器。但是g ++编译器默认为98版本。要以C ++ 14运行它,我们需要在终端中添加 -std = c ++ 14

I know that we can compile program as C++ using g++ compiler. But g++ compiler defaults to 98 version. To run it as C++ 14, we need to add -std=c++14 in terminal.

Sublime Text由于其轻量级和功能而被视为一个有价值的编辑器,用于竞争性编程。在这些比赛中,时间是重要的,因此时间浪费在文本文件中复制,然后从终端运行。与98相比,C ++ 14具有丰富的库和其他重要的特性。因此,人们希望能够在Sublime文本和C ++ 14上编译代码。

Sublime Text is considered a valuable editor for competitive programming due to its light weight and features. In these competitions time is important and thus the time is wasted in copying in text file and then running from terminal. C++ 14 features a rich library and other important features in comparison to 98. Thus one would desire to be able to compile the code on sublime text and as C++ 14.

但是我如何确保当我编译Sublime Text 3中的代码时,它编译为默认为C ++ 14?

But how can I make sure that when I compile the code within Sublime Text 3, it compiles as default to C++14?

解决方案 -


  1. 转到软件包并解压C ++。sublime-package

  2. 打开C ++单文件。 sublime-build

  3. 更改

  1. Go to packages and extract C++.sublime-package
  2. Open C++ Single File.sublime-build
  3. Change

"shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\""

"shell_cmd": "g++ -std=c++14 \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\""

添加 -std = c + +14

Added -std=c++14 in both build and run






这是正确的方法吗?


Is this the right way to do so? It is named as single file - Is this something to worry about if I want to use multiple files ?

推荐答案

最好创建一个文件一个新的构建系统,如下:

It's better to create a new build system, here's how:

点击 Tools - >构建系统 - >新的构建系统

这是我使用的(注意 -std = c ++ 14

This is what I use (notice the flag -std=c++14)

{
 "cmd":["bash", "-c", "g++ -std=c++14 -Wall '${file}' -o '${file_path}/${file_base_name}' && '${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++14 '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
   }
 ]
}

(我相信你可以使用你已经有的行,并将它保存到一个新的构建系统文件。)

(I believe you can just use the line you already have and save it to a new build system file.)

现在保存新版本,在 Tools - >构建系统

现在,您可以使用 CTRL + B

Now save the new build, select it in Tools -> Build System.
And now you can build and run with CTRL + B

这篇关于将Sublime Text 3中的程序编译为c ++ 14作为默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆