Sublime具有用于c ++程序的控制台输入的文本 [英] Sublime Text with console input for c++ programs

查看:994
本文介绍了Sublime具有用于c ++程序的控制台输入的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在SublimeText 2.0.1中使用控制台输入?
我选择了工具 - >构建系统 - > C ++,并添加hello.cpp文件到项目:

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;
}


$ b <行std :: cin >> a >> b;被传递,我不能输入值。
在g ++的终端运行良好。
OS:Ubuntu 12.04

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

推荐答案

我不认为stdin在Sublime Text中是支持的,文件 stdin.input 并在编辑器下使用它:

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;
}

这篇关于Sublime具有用于c ++程序的控制台输入的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆