默认情况下,将程序编译为Sublime Text 3中的c ++ 14

时间:2016-05-09 14:36:55

标签: c++ compilation sublimetext3 sublimetext c++14

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

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

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

经过一番摆弄后,我提出了以下解决方案 -

  1. 转到包并提取C ++。sublime-package
  2. 打开C ++ Single File.sublime-build
  3. 更改

    "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}\""
    

    在构建和运行

  4. 中添加了-std=c++14
  5. 保存并覆盖最初在Sublime Text 3中的包
  6. 这是正确的方法吗?它被命名为单个文件 - 如果我想使用多个文件,这是否需要担心?

3 个答案:

答案 0 :(得分:6)

最好创建一个新的构建系统,具体如下:

点击def read_from_csv(filename_queue): reader = tf.TextLineReader() _, csv_row = reader.read(filename_queue) record_defaults = [[""],[0]] image_path, label = tf.decode_csv(csv_row, field_delim=" ", record_defaults=record_defaults) # here's where I need to read the file somehow... image = tf.read_file(image_path) # I probably need this somewhere print(image) # Tensor("DecodeJpeg:0", shape=(?, ?, 3), dtype=uint8) image = tf.image.decode_jpeg(image, channels=3) return image, label

这是我使用的(注意标志Tools -> Build System -> New Build System

-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}'"] } ] } 中选择它 现在,您可以使用Tools -> Build System

构建和运行

答案 1 :(得分:1)

通常,编辑默认文件很糟糕。 只需创建一个新的构建系统托盘 - >构建:新构建系统 在那里添加您的更改并根据需要保存。 然后,当您想要使用它时,只需选择Build With :(新建系统名称) 如果您还需要Build - Run选项,请改用此代码:

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

}

答案 2 :(得分:1)

编辑默认文件的最佳方法是使用PackageResourceViewer

安装完成后,从PackageResourceViewer: Open Resource运行command palette命令。您将看到一个包列表,您可以导航到该列表以选择要编辑的文件。

所选文件将在新文档中打开,任何更改都将保存到位于Packages/PackageThatYouEdited/FileThatYouEdited.ext

的新文件中

此方法的好处是Packages中的已编辑文件现在将覆盖sublime-package文件中的原始文件,但原始文件将保持不变。如果您选择删除已编辑的文件,sublime-package中的原始文件将再次处于活动状态。