Sublime text 3 - 编译程序并在终端中运行

use*_*841 11 c++ compiler-construction ubuntu sublimetext3

我正在使用Ubuntu 12.04,我想知道,是否有可能从终端自动运行c ++程序?当你不得不在构建控制台中使用它时,它真的很糟糕,因为有时候我会意外地创建无限循环,并且必须重新启动sublime文本再次工作.我正在使用Sublime文本3.

Mat*_*DMo 20

Sublime Text 3包含两个您可能感兴趣的构建系统:C++和Make.该C++.sublime-build文件如下:

{
    "shell_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",
            "shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\""
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

要使用它,请转到Tools -> Build System并选择C++.您现在可以使用它CtrlB来运行构建(top命令)或CtrlShiftB运行Run变体.

  • 如果代码需要一些用户输入怎么办? (5认同)

小智 7

{
  "cmd": ["g++", "$file", "-o", "${file_path}/${file_base_name}"],
  "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
  "working_dir": "${file_path}",
  "selector": "source.c, source.c++, source.cxx, source.cpp",
  "variants":
  [
      {
          "name": "Run",
          "shell": true,
          "cmd": ["gnome-terminal -e 'bash -c \"${file_path}/${file_base_name};echo;echo;  echo Press ENTER to continue; read line;exit; exec bash\"'"]
      }
  ]    
}
Run Code Online (Sandbox Code Playgroud)

它可以在终端运行并从键盘输入数据