Page 17 - Data Structures Interactive Book
P. 17
to redefine a method from its base class. Polymorphism enhances flexibility and enables
dynamic behavior in programs, which is particularly useful in designing frameworks and
libraries.
1.3 Input/Output in C++
Input and output (I/O) operations are fundamental to any programming language, as
they allow interaction between the program and the user or external systems. In C++, I/O is
handled through streams, which represent sequences of data flowing into or out of the
program. The most used streams are cin for input and cout for output, both provided by the
<iostream> library. Additionally, C++ supports file handling through the <fstream> library,
enabling programs to store and retrieve data persistently.
1.3.1 cin and cout
The cin object is used to read input from the keyboard, while the cout object is used
to display output on the console. Both are part of the standard input/output stream library.
These objects simplify user interaction by providing straightforward syntax for reading and
writing data.
Example:
In this example, the program prompts the user to enter a number, stores the input in
the variable number, and then displays it using cout.
17

