Sublime Text with console input for C ++ programs

How to use console input in SublimeText 2.0.1? I'v selected "Tools β†’ Build System β†’ C ++" and add the hello.cpp file to the project:

#include <iostream> int main() { int a, b, c; std::cout << "Enter: "; std::cin >> a >> b; c = a + b; std::cout << a << '+' << b << '=' << c << std::endl; return 0; } 

Build successfully, but when I run ("Tools-> Run"), the line is "std :: cin β†’ a β†’ b;" and I can’t enter the values. In a terminal with g ++, it works well. OS: Ubuntu 12.04

+7
source share
2 answers

I do not think that stdin is supported in Sublime Text, however you can create the stdin.input file and use it under the editor:

 #include <iostream> #include <fstream> #define SUBLIME #if defined SUBLIME # define ISTREAM ifile #else # define ISTREAM std::cin #endif int main() { int a, b, c; std::cout << "Enter: "; #if defined (SUBLIME) std::ifstream ifile("stdin.input"); #endif ISTREAM >> a >> b; c = a + b; std::cout << a << '+' << b << '=' << c << std::endl; return 0; } 
+2
source

The only error I see is that your missing int c; And if that doesn't work, try returning 0; instead of returning 1;

+1
source

All Articles