Object Oriented Programming: Chapter 6: IO Systems and File IO

Concept of Streams

C++ Object Oriented Programming

When C program begins execution three predefined streams are automatically opened and those are stdin, stdout, stderr and when C++ program begins four streams get opened ‒ cin, cout, cerr and clog.

Chapter :6

I/O Systems and File I/O

 

Concept of Streams

•  Stream is basically a channel on which data flow from sender to receiver. Data can be sent out from the program on an output stream or received into the program on an input stream. For example, at the start of a program, the standard input stream "cin" is connected to the keyboard and the standard output stream "cout" is connected to the screen. In fact, input and output streams such as "cin" and "cout" are examples of stream objects. In C++ the entire I/O (Input/Output) system operates through streams. A stream is connected to a physical device by the C++ input output system (Popularly known as I/O system).

• When C program begins execution three predefined streams are automatically opened and those are stdin, stdout, stderr and when C++ program begins four streams get opened ‒ cin, cout, cerr and clog.

Stream     Meaning                 Physical device

cin       :    Standard input   ‒   Connected to Keyboard

cout     :  Standard output   ‒   Connected to Screen

cerr     :   Standard error     ‒     Connected to Screen

clog     :   Buffer of error   ‒    Connected to Screen

The header file named iostream.h supports these I/O operations.

 

Example:1

How do the I/O facilities in C++ differ from that of C?

Solution :



I/O Facilities in C

1. In C, scanf() and printf() are only used for built in datatypes for performing input and output.

2. For supporting the Input/Output operations we have to include#include<stdio.h>

3. The predefined streams used in C are stdin,stdout, stderr

I/O Facilities in C++

1. In contrast, C++ supports generic I/O facilities called C++ stream I/O.

2. For supporting the Input/Output operations we have to include#include<iostream> //for interactive I/O#include<iomanip> //for format control#include<fstream> //for file I/Ousing namespace std; //for bringing the names of //included library facilities into your working //namespace

3.The predefined streams used in C++ are cin,cout, cerr, clog

 

Object Oriented Programming: Chapter 6: IO Systems and File IO : Tag: Oops, Computer Programming : C++ Object Oriented Programming - Concept of Streams


Object Oriented Programming: Chapter 6: IO Systems and File IO



Under Subject


Object Oriented Programming (OOPs)

CS25C07 2nd Semester CSE, CSE(CY) Depts | 2025 Regulation | 2nd Semester 2025 Regulation



Related Subjects


English Essentials II

EN25C02 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation



Linear Algebra

MA25C02 2nd Semester | 2025 Regulation


Applied Physics (CSIE) II

PH25C03 2nd Semester AIDS, CSE, IT, CSE(CY) Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Digital Principles and Computer Organization

CS25C06 2nd Semester AIDS, CSE, IT, CSE(CY) Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Basic Electrical and Electronics Engineering

EE25C01 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation


Object Oriented Programming (OOPs)

CS25C07 2nd Semester CSE, CSE(CY) Depts | 2025 Regulation | 2nd Semester 2025 Regulation


Re-Engineering for Innovation

ME25C05 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation


Object Oriented Programming (OOPs) - Laboratory

CS25C07 2nd Semester CSE, CSE(CY) Depts | 2025 Regulation | 2nd Semester 2025 Regulation