Ily*_*hyk 7 c++ gcc sublimetext2
如何在SublimeText 2.0.1中使用控制台输入?我选择了"工具 - >构建系统 - > C++",并将hello.cpp文件添加到项目中:
#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;
}
Run Code Online (Sandbox Code Playgroud)
构建成功,但是当我运行时("工具 - >运行"),行"std :: cin >> a >> b;" 传递,我不能输入值.在带有g ++的终端中运行良好.操作系统: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;
}
Run Code Online (Sandbox Code Playgroud)