Files
In this lesson, we will cover reading from and writing to files.
Need for file handling #
We have seen in the previous lesson that the standard input and output streams can be redirected to and from files and other programs with the >
, <
and |
operators on the terminal. Despite being very powerful, these tools are not suitable in every situation because in many cases programs can not complete their tasks simply by reading from their input and writing to their output.
For example, a program that deals with student records may use its standard output to display the program menu. Such a program may need to search, update or delete specific records for later use. Therefore, this information needs to be stored in files.
Fundamental concepts #
Files are represented by the File
struct of the std.stdio
module. Since structs ...