How do I read console input / stdin in Dart?

前端 未结 4 877
你的背包
你的背包 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:50

    The readLineSync() method of stdin allows to capture a String from the console:

    import 'dart:io';
    
    main() {
        print('1 + 1 = ...');
        var line = stdin.readLineSync(encoding: Encoding.getByName('utf-8'));
        print(line.trim() == '2' ? 'Yup!' : 'Nope :(');
    }
    

提交回复
热议问题