Welcome to the Linux Foundation Forum!

LFEL1002 - Mismatch between code example and explanation

Options

In the chapter "More Complex Syntax", I am a bit confused at the example "File I/O and Stdout". The explanation contains these points:

  • Import Modules
    We import the required modules from the standard library. BufRead and BufWriter are used for buffered reading and writing, respectively, which is more efficient than handling one byte at a time.

  • Opening Output File
    We use File::create() to create (or truncate) the output file. A BufWriter is used for efficient writing.

  • Reading and Writing
    We read each line from the input file, prepend it with a line number, and then write it to both the standard output (stdout) and the output file.

The mentioned BufWriter in the two first bullet points is not part of the code example. The last bullet point explains the output actions, but the code does something different. It reads each line and parse it as an i32. Then in multiplies this integer by 2 and writes in to the output file.

Do I understand the code example correctly and is the explanation wrong or the otherway round?

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Categories

Upcoming Training