Nim language provides a Stdin library to read input data from a user.
This tutorial explains multiple ways to read input data from a user and solve the below questions. How to read from the stdin with the nim script? How to get input from the console in Nim?
Nim How to read input data from a user?
readLine procedure works with
stdin is a variable system module that refers standard input stream such as a file or console.
stdin.readLine() both functions read data from a console and assign it to a variable. It reads a single line of data from
These methods always read the data as a
readLine(stdin) stops the program execution and waits for user input until enter is pressed.
echo "Enter Name:" let name = readLine(stdin) echo "User entered string: ", name
Enter Name: Eric User entered string: Eric
How to read user input as a number in Nim with an example
readLine() method reads data from the standard input stream as a string.
integer using the
Finally, Print the integer to console
Here is an example
import strutils echo "Enter Age:" let age = readLine(stdin).parseInt() echo "Age is ", age
Enter Age: 22 Age is : 22