How can I use console input in SublimeText 2.0.1? I'v chosen "Tools -> Build System -> C++", and add 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 successful, but when I run ("Tools->Run"), the line "std::cin >> a >> b;" is passed and I can't enter the values. In terminal with g++ it run well. OS: Ubuntu 12.04
I don't think stdin is supported in Sublime Text, however, you can create a file stdin.input
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With