The C++ I/O system provides a unified interface for handling various devices through streams, which are sequences of bytes used for input and output operations. The system includes stream classes defined in the iostream header file, with istream for input and ostream for output, utilizing overloaded operators for data handling. Additionally, functions like get() and getline() facilitate character and line-oriented input/output operations.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
2 views
Chapter 10
The C++ I/O system provides a unified interface for handling various devices through streams, which are sequences of bytes used for input and output operations. The system includes stream classes defined in the iostream header file, with istream for input and ostream for output, utilizing overloaded operators for data handling. Additionally, functions like get() and getline() facilitate character and line-oriented input/output operations.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2
10.
Managing Console I/O
Operations The I/O system in C++ is designed to work with a wide variety of devices including terminals, disks, and tape drives. Although each device is very different, the I/O system supplies an interface to the programmer that is independent of the actual device being accessed. This interface is known as stream.
A stream is a sequence of bytes. It acts either as a source
from which the input data can be obtained or as a destination to which the output data can be sent. The source stream that provides data to the program is called the input stream and the destination stream that receives output from the program is called the output stream. In other words, a program extracts the bytes from an input stream and Inserts bytes into an output stream.
The C++ I/O system contains a hierarchy of classes that are
used to define various streams to deal with both the console and disk files. These classes are called stream classes. These classes are declared in the header file iostream. This file should be included in all the programs that communicate with the console unit.
The class istream provides the facilities for formatted and
unformatted input while the class ostream provides the facilities for formatted output. The class iostream provides the facilities for handling both input and output streams.
The >> operator is overloaded in the istream class and <<
is overloaded in the ostream class. The classes istream and ostream define two member functions get() and put() respectively to handle the single character input/output operations . There are two types of get() functions. We can use both get(char *) and get(void) prototypes to fetch a character including the blank space, tab and the newline character. The get(char *) version assigns the input character to its argument and the get(void) version returns the input character.
We can read and display a line of text more efficiently using
the lineoriented input/output functions getline() and write(). The getline() function reads a whole line of text that ends with a newline character.