How do I read console input / stdin in Dart?

前端 未结 4 876
你的背包
你的背包 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 22:57

    import 'dart:io';
    
    void main(){
      stdout.write("Enter your name : ");
      var name = stdin.readLineSync();
      stdout.write(name);
    }
    

    Output

    Enter your name : Jay
    Jay
    

    By default readLineSync() takes input as string. But If you want integer input then you have to use parse() or tryparse().

提交回复
热议问题