How do I read console input / stdin in Dart?

前端 未结 4 873
你的背包
你的背包 2021-02-03 21:58

How do I read console input from stdin in Dart?

Is there a scanf in Dart?

4条回答
  •  花落未央
    2021-02-03 23:01

    The following should be the most up to date dart code to read input from stdin.

    import 'dart:async';
    import 'dart:io';
    import 'dart:convert';
    
    void main() {
      readLine().listen(processLine);
    }
    
    Stream readLine() => stdin
        .transform(utf8.decoder)
        .transform(const LineSplitter());
    
    void processLine(String line) {
      print(line);
    }
    

提交回复
热议问题