热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

SublimeText编译运行C++语言程序出现无法输入解决办法(WindowsLinuxMacOS均适用)

篇首语:本文由编程笔记#小编为大家整理,主要介绍了Sublime Text编译运行C++语言程序出现无法输入解决办法(WindowsLinuxMacOS均适用)相关的知识,希望对你有一定的参考价值。

篇首语:本文由编程笔记#小编为大家整理,主要介绍了Sublime Text编译运行C++语言程序出现无法输入解决办法(WindowsLinuxMacOS均适用)相关的知识,希望对你有一定的参考价值。








文章目录


  • 项目场景
  • 问题描述
  • 解决方案
    • Windows系统
    • MacOS系统
    • Linux系统

  • 运行测试





项目场景

最近把电脑上的 SublimeText 编辑器更新到最新版了,在编译处理 C 语言程序时,发现只要是包含 scanfcin 等需要我们手动输入的程序,编译是没问题的,但是在 SublimeText 里运行会出现无法从命令行输入的情况,在外部运行可执行程序是没问题的。




问题描述

在使用 SublimeText 编译运行这段代码,我们可以看到无论在命令行中如何输入都读取不进去:

但是我在外部终端中直接运行编译生成的可执行文件 test,是可以运行的,说明是 SublimeText 那边的问题:




解决方案

自己重新创建一个C++的编译器:打开SublimeText → Tools → Build System → New Build System

考虑到篇幅问题C语言的我放在另一篇博客了:Sublime Text编译运行C语言程序出现无法输入解决办法(Windows、Linux、MacOS均适用)


Windows系统

Windows系统写入如下内容到文件内:


"windows":
"cmd": ["g++", "-std=c++11", "$file", "-o", "$file_base_name.exe"],
,
"cmd": ["g++", "-std=c++11", "$file", "-o", "$file_base_name"],
"file_regex": "^(.*)\\\\(([0-9]+),([0-9]+)\\\\) (Error|Fatal): (.*)$",
"working_dir": "$file_path",
"selector": "source.c++",
"variants": [

"name": "Run",
"shell": true,
"windows":
"shell_cmd" : "start cmd /c \\"\\"$file_base_name.exe\\" & echo. & pause\\""

,

"name": "Build and Run",
"shell": true,
"windows":
"shell_cmd": "g++ -std=c++11 \\"$file\\" -o \\"$file_base_name.exe\\" && start cmd /c \\"\\"$file_base_name.exe\\" & echo. & pause\\""
,

]


MacOS系统

MacOS系统写入如下内容:


"cmd": ["g++", "-std=c++11", "$file", "-o", "$file_base_name"],
"file_regex": "^(.*)\\\\(([0-9]+),([0-9]+)\\\\) (Error|Fatal): (.*)$",
"working_dir": "$file_path",
"selector": "source.c++",
"osx":
"path": "/usr/local/bin:/usr/bin:/bin:$path",
"cmd": ["clang++", "-std=c++11", "$file", "-o", "$file_base_name"],
,
"variants": [

"name": "Run",
"shell": true,
"osx":
"shell_cmd": "echo 'cd \\"$file_path/\\"' > '/tmp/$file_base_name' && echo './\\"$file_base_name\\"' >> '/tmp/$file_base_name' && echo read >> '/tmp/$file_base_name' && chmod +x '/tmp/$file_base_name' && open -a Terminal.app '/tmp/$file_base_name'"
,

,

"name": "Build and Run",
"shell": true,
"osx":
"shell_cmd": "clang++ -std=c++11 '$file' -o '$file_base_name' && echo 'cd \\"$file_path/\\"' > '/tmp/$file_base_name' && echo './\\"$file_base_name\\"' >> '/tmp/$file_base_name' && echo read >> '/tmp/$file_base_name' && chmod +x '/tmp/$file_base_name' && open -a Terminal.app '/tmp/$file_base_name'"
,

]


Linux系统

Linux系统写入如下内容:


"cmd": ["g++", "-std=c++11", "$file", "-o", "$file_base_name"],
"file_regex": "^(.*)\\\\(([0-9]+),([0-9]+)\\\\) (Error|Fatal): (.*)$",
"working_dir": "$file_path",
"selector": "source.c++",
"variants": [

"name": "Run",
"shell": true,
"linux":
"cmd": ["gnome-terminal -- bash -c \\"\\\\\\"./$file_base_name\\\\\\";echo ;read line;exit; exec bash\\""]
,
,

"name": "Build and Run",
"shell": true,
"linux":
"cmd": ["g++ -std=c++11 \\"$file\\" -o \\"$file_base_name\\" && gnome-terminal -- bash -c \\"\\\\\\"./$file_base_name\\\\\\";echo ; read line; exit; exec bash\\""]
,

]

保存文件到其给定位置(不要自己变更位置),命名为 MyC++.sublime-build




运行测试

接着我们在编译前,Tools → Build System → 勾选MyC++,使用 Ctrl+B 选择 Build and Run 便可以正常出结果了。







推荐阅读
author-avatar
粉笔画1995_996
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有