Course of Raku / Objects, I/O, and exceptions / Input and output / File handles / Exercises

Number the lines

Problem

Write the three words apple, banana, and cherry, each on its own line, to a file called words.txt. Then read the file line by line and print each line prefixed with its line number (starting from 1), in the form <number>: <line>.

Example

The program prints:

1: apple
2: banana
3: cherry

Solution

See the solution

Course navigation

File handles   |   Solution: Number the lines