September 2026
1051 pages
35h 4m
English
First, we’ll describe how you can read data from a file. To do this, we need to access that file in read-only mode. The test file we’ll use in this example is a dictionary that contains in each line an English word and, separated from it by a space, its German translation. The file should be named dictionary.txt:
Spain SpanienGermany DeutschlandSweden SchwedenFrance FrankreichItaly Italien
In the program, we want to prepare the data in this file so that we can conveniently access it later in a dictionary.[ 20 ] As a little extra, we’ll extend the program to allow the user to ask the program for the translation of an English term.
First, the file must be opened for reading. ...
Read now
Unlock full access