I’m new to sublime. I’m not sure how to get cin to work for c++. I’ve figured out that the console in sublime can’t accept input but I am curious if there is a work around that I’m not seeing.
Thank you
I’m new to sublime. I’m not sure how to get cin to work for c++. I’ve figured out that the console in sublime can’t accept input but I am curious if there is a work around that I’m not seeing.
Thank you
With core Sublime you can use input redirection in the sublime-build
file to send the contents of a file into the stdin
of your program. For example, this would execute the program sending the contents of the file input.txt
in:
{
"shell_cmd": "myprogram < input.txt",
"working_dir": "${file_path}",
"selector": "source.c++",
}
Another way to do something like this is the Terminus package, which is free, cross platform and implements a terminal directly into Sublime. You can use it in a build system to run anything interactive.
This video shows how to do that (the example in the video is Python, but the same steps will work if you choose the build system you’re currently using, which might be C++ Single File.sublime-build
if you’re not sure):
Dude, this is perfect. Thank you so much. Its just what I was looking for! You just got yourself a new subscriber btw.