Page 259 - DCAP404 _Object Oriented Programming
P. 259
Object-oriented Programming Ajay Kumar Bansal, Lovely Professional University
Notes Unit 12: Console I/O
CONTENTS
Objectives
Introduction
12.1 Concept of Streams
12.2 Hierarchy of Console Stream Classes
12.3 Unformatted I/O Operations
12.4 Managing Output with Manipulators
12.4.1 Manipulate Function
12.4.2 Predefined Manipulators
12.5 Summary
12.6 Keywords
12.7 Review Questions
12.8 Further Readings
Objectives
After studying this unit, you will be able to:
Recognize the concepts of streams
Describe the hierarchy of console stream classes
Explain the unformatted I/O operations
Discuss the managing output with manipulators
Introduction
One of the most essential features of interactive programming is its ability to interact with the
users through operator console usually comprising keyboard and monitor. Accordingly, every
computer language (and compiler) provides standard input/output functions and/or methods
to facilitate console operations.
C++ accomplishes input/output operations using concept of stream. A stream is a series of bytes
whose value depends on the variable in which it is stored. This way, C++ is able to treat all the
input and output operations in a uniform manner. Thus, whether it is reading from a file or from
the keyboard, for a C++ program it is simply a stream.
We have used the objects cin and cout (predefined in the iostream.h file) for the input and output
of data of various types. This has been made possible by overloading the operators >> and << to
recognize all the basic C++ types. The >> operator is overloaded in the istream class and << is
overloaded in the ostream class. The following is the general format for reading data from the
keyboard:
cin >> variable1 >> variable2 >>.. ...>> variableN;
252 LOVELY PROFESSIONAL UNIVERSITY