Good day. I started using the above editor to write a lab in C ++, I ran into a problem. Suppose I compile a program.

#include <iostream> using namespace std; int main() { int a,b; cout<<"Введите a,b"<<endl; cin>>a>>b; cout<<a+b<<endl; return 0; } 

And here comes the problem. Ctrl + B, then Ctrl + Shift + B (Build & Run). The program compiles, runs itself from somewhere takes values, counts and closes. Question: how to make the sublime text console let me enter values ​​myself? Those. make it work with input stream.

  • Yyyyy. Are you sure that this is a question on our forum? - VladD
  • help, write on Windows ... I can’t do it ... - user27838

1 answer 1

depending on which axis. If under Linux, then create your own "build system" Tools->Build System->New Build System . Content can be honestly copied from C++.sublime-build (which is in ~/.config/sublime-text-2/Packages/C++ . Here is an example of a converted

 { "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", "cmd": ["bash", "-c", "g++ '${file}' -o '${file_path}/${file_base_name}' && 'gnome-terminal -e ${file_path}/${file_base_name}'"] } ] } 

there is only one addition - gnome-terminal -e , which will force the program to run in a separate terminal. If you like another terminal - just specify it, most of the terminals in Linux understand the -e option. (for example xterm ).

For Windows, it will be the same, just need to peek at the correct parameters to run and replace gnome-terminal with cmd

  • Thank. And to force to understand input the St2 console is impossible? + you have a little mistake. Not there is a quotation mark gnome-terminal -e '$ {file_path} / $ {file_base_name}' " - skad0
  • That is, without opening an additional terminal? I think no. But no one bothers to redirect input. But sometimes for small labs, a site like http://liveworkspace.org/ may be more useful. There and input can be redirected. - KoVadim