Reading from the Standard Input
Understand how to read data from standard input in D by using variables and the readf function. Learn to manage whitespace in input, store values correctly, and handle format specifiers for various data types to build interactive programs.
We'll cover the following...
stdout
As we’ve seen in the previous chapter, we don’t need to type stdout when displaying the output because it is implied. What needs to be displayed is specified as an argument. So, the statement write(studentCount) is sufficient to print the value of studentCount.
To summarize:
Any data that is read by the program must first be stored in a variable. For example, a program that reads the number of students from the input must store this information in a variable. The type of this specific variable can be int.
readf
The reverse of write is readf; it reads from the standard input. The ‘f’ in its name comes from “formatted” because what it reads must always be presented in a certain format. In the previous lesson, we’ve also seen that the standard input stream is stdin.
In the case of reading, one piece of the puzzle is still missing: where to store the data that is read.
To summarize: