zoukankan      html  css  js  c++  java
  • 【前端】使用readline模块实现Node.js的输入输出

    'use strict';
    
    function f(x) {
        // do something...    
    }
    
    var readline = require('readline');
    
    //创建readline接口实例
    var rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    
    // ======= 方法一 =========
    rl.question("input something:",function(str){
        console.log(f(str));
    
        // 不加close,则不会结束
        rl.close();
    });
    // =======================
    // 或者这样:
    // ======= 方法二 =========
    // console.log('input something:');
    // rl.on('line', function(line){
    //     console.log(f(line));
    
    //     // 不加close,则不会结束
    //     rl.close();
    // });
    // ======================
    
    rl.on('close', function() {
        process.exit(0);
    });
    
  • 相关阅读:
    POJ
    POJ
    操作系统
    POJ
    POJ
    codeforces Educational Round 89
    codeforces Round 647(div. 2)
    codeforces Educational Round 88
    后缀自动机简单总结
    dsu on tree 简单总结
  • 原文地址:https://www.cnblogs.com/forzhaokang/p/5288947.html
Copyright © 2011-2022 走看看