Sublime Text with console input for c++ programs
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
我不认为Sublime Text支持stdin,但是,您可以创建一个stdin.input
文件并在编辑器中使用它:
#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;
}
The only error I see is that your missing int c; And if that doesn't work maybe try return 0; instead of return 1;
链接地址: http://www.djcxy.com/p/11002.html上一篇: 安全解析数字和语言环境
下一篇: 崇高的文本与c + +程序的控制台输入