Minh Pham Minh Pham - 8 months ago 50
C++ Question

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. 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.

"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++",

        "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. Choose as Build System C++11 and it should do the job.