VOOZH about

URL: https://www.geeksforgeeks.org/dart/dart-standard-input-output/

⇱ Dart - Standard Input Output - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Dart - Standard Input Output

Last Updated : 24 Mar, 2025

In Dart programming language, you can take standard input from the user through the console via the use of the .readLineSync() function. To take input from the console you need to import a library, named dart:io from the libraries of Dart.

Stdin Class

This class allows the user to read data from standard input in both synchronous and asynchronous ways. The method readLineSync() is one of the methods used to take input from the user. Refer to the official doc for other methods, from here.

- :


Input:

Geek

Output:

Enter your name?
Hello, Geek! 
Welcome to GeeksforGeeks!!


- :


Input:

01

Output:

Enter your favourite number:
Your favourite number is 1


Standard Output in Dart

In Dart, there are two ways to display output in the console: 

  1. Using print statement.
  2. Using stdout.write() statement.

Printing Output in two different ways:


Output:

Welcome to GeeksforGeeks! // printing from print statement
Welcome to GeeksforGeeks! // printing from stdout.write()

Note: The print() statement brings the cursor to the next line while stdout.write() don't bring the cursor to the next line, it remains in the same line.
If the print statements are switched in the above program then:  

Output:

// printing from stout.write() and print() statement respectively
Welcome to GeeksforGeeks! Welcome to GeeksforGeeks!


Making a simple addition Program

Input:

11
12

Output:

-----------GeeksForGeeks-----------
Enter first number
Enter second number
Sum is 23

In Dart, use stdin.readLineSync() from the dart:io library to handle user input, which can be either strings or numbers. The Stdin class supports synchronous and asynchronous input. For output, use print() to move to a new line or stdout.write() to stay on the same line. These methods enable efficient console interactions, including basic arithmetic operations like addition.

Comment
Article Tags:
Article Tags:

Explore