微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Sublime Text,带有c程序的控制台输入

如何在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;
}

建立成功,但当我运行(“工具 – >运行”)时,行“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,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;
}

原文地址:https://www.jb51.cc/html/232087.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐