简体   繁体   English

用Sublime Text 2中的输入运行C ++文件

[英]Run C++ file with input in Sublime Text 2

After compilation of C++ source code, I want to run it with an input file through the sublime text command. 编译C ++源代码后,我想通过sublime text命令在输入文件中运行它。 How can this be done? 如何才能做到这一点?

If you mean a parameter after your C++ build file, I have found a way to do this in a dodgy way... I created a new build system for c++11 and added the input file (see input_file below) to the Run section. 如果您在C ++生成文件后指一个参数,那么我已经找到了一种狡猾的方式来执行此操作...我为c ++ 11创建了一个新的生成系统,并将输入文件(请参见下面的input_file)添加到Run部分。

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

Save the file, as for example C++11.sublime-build , in $HOME/.config/sublime-text-2/Packages/User . 将文件(例如C++11.sublime-build )保存在$HOME/.config/sublime-text-2/Packages/User Choose as Build System C++11 and it should do the job. 选择作为Build System C ++ 11,它应该可以完成工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM