SlideShare a Scribd company logo
1 of 22
Stream Classes
IN
C++
BY
Roll No:-
11
13
14
15
What Is C++?
▪ C++, as the name suggests, is a superset of C.
▪ C++ can run most of C code while C cannot run C++ code.
▪ C follows the Procedural Programming Language(POP)
▪ while C++ is a language(procedural as well as object oriented)
▪ In C the data is not secured while in C++ data is secured(hidden) .
▪ Encapsulation OF Data Is Done In C++
▪ In C Importance is given on doingThings(Algorithm) While In C++
importance are given on Data (Object).
▪ C uses the top-down approach while C++ uses the bottom-up
approach.
What Is Stream?
What is its needs in c++?
A stream is nothing but a flow of data.
In the object-oriented programming, the streams are controlled using
the classes.The operations with the files mainly consist of two types.
They are read and write.
C++ provides various classes, to perform these operations.
The ios class is the base class. All other classes are derived from the ios
class.These classes contain several member functions that perform
input and output operations.
Different streams are used to represent
different kinds of data flow.
Each stream is associated with a particular
class, which contains member functions and
definitions for dealing with that particular kind
of data flow.
The stream that supplies data to the program in
known as an input stream. It reads the data
from the file and hands it over to the program.
The stream that receives data from the program
is known as an output stream. It writes the
received data to the file
The following Figure illustratesThis.
The Istream and ostream classes
control input and output functions,
respectively.
The ios is the base class of these two
classes.
The member
functions of these classes handle
formatted and unformatted operations.
ios
Istream
Used for INPUT
function
Ostream
Used for Output
Function
File Class Hierarchy
ios
istream ostream
iostream
ifstream fstream ofstream
iostream.h
fstream.h
Input
Output
File I/O
Multiple inheritanceBase Class
steambuf
filebuf
Header file Brief description
<iostream>
Provide basic information required for all stream I/O operation such as cin, cout, cerr and clog
correspond to standard input stream, standard output stream, and standard unbuffered and
buffered error streams respectively.
<iomanip>
Contains information useful for performing formatted I/O with parameterized stream manipulation.
<fstream> Contains information for user controlled file processing operations.
<strstream>
Contains information for performing in-memory formatting or in-core formatting. This resembles
file processing, but the I/O operation is performed to and from character arrays rather than files.
<stdiostrem>
Contains information for program that mixes the C and C++ styles of I/O.
iostream Library
DataType Description
ofstream
This data type represents the output file
stream and is used to create files and to write
information to files.
ifstream
This data type represents the input file stream
and is used to read information from files.
fstream
This data type represents the file stream
generally, and has the capabilities of both
ofstream and ifstream which means it can
create files, write information to files, and
read information from files.
To perform file processing in c++, header files <iostream> and <fstream> must be included in your c++ source
file.
DataTypes In Ostream class
This data types requires another standard C++ library called fstream, which defines three new data types:
Mode Flag Description
ios::app
Append mode. All output to that file to be
appended to the end.
ios::ate
Open a file for output and move the
read/write control to the end of the file.
ios::in Open a file for reading.
ios::out Open a file for writing.
ios::trunc
If the file already exists, its contents will be
truncated before opening the file.
Mode Flag Of iostream
Opening a File:
A file must be opened before you can read from it or write to it. Either the ofstream or
fstream object may be used to open a file for writing
And
ifstream object is used to open a file for reading purpose only.
void open(const char *filename, ios::openmode mode);
Closing a File
When a C++ program terminates it automatically closes flushes all the streams, release all the allocated memory
and close all the opened files. But it is always a good practice that a programmer should close all the opened files
before program termination.
Following is the standard syntax for close() function, which is a member of fstream, ifstream, and ofstream objects.
void close();
Operators Brief description
cin Object of istream class, connected to the standard input device, normally the keyboard.
cout
Object of ostream class, connected to standard output device, normally the
display/screen.
cerr
Object of the ostream class connected to standard error device. This is unbuffered output,
so each insertion to cerr causes its output to appear immediately.
clog Same as cerr but outputs to clog are buffered.
Writing to a File:
The left shift operator (<<) is overloaded to designate stream output and is called stream insertion operator.
write information to a file from your program using the
stream insertion operator (<<) just as you use that operator to output information to the
screen.The only difference is that you use an of stream or fstream object instead of the cout object.
Reading from a File:
The right shift operator (>>) is overloaded to designate stream input and is called stream extraction
operator.
You read information from a file into your program using the stream extraction operator (>>)
just as you use that operator to input information from the keyboard.The only difference is that you use an
Ifstream or Fstream object instead of the Cin object.
Read &Write Example:-
// string output using <<
#include <iostream>
void main()
{
cout<<"Welcome to C++ I/O module!!!"<<endl;
cout<<"Welcome to ";
cout<<"C++ module 18"<<endl;
// endl is end line stream manipulator
}
 Stream output program example:-
Output:
 Stream input program example:-
#include <iostream.h>
void main()
{
int p, q, r;
cout << "Enter 3 integers separated by space: n";
cin>>p>>q>>r; // the >> operator skips whitespace characters
cout<<"Sum of the "<<p<<","<<q<<" and "<<r<<" is = "<<(p+q+r)<<endl;
} Output:
From File Read &Write Example using fstream class
#include <fstream>
#include <iostream>
using namespace std;
int main ()
{
char data[100];
ofstream outfile;
outfile.open("afile.dat"); // open a file in write mode.
cout << "Writing to the file" << endl;
cout << "Enter your name: ";
cin.getline(data, 100);
outfile << data << endl;
cout << "Enter your age: "; // write inputted data into the file.
cin >> data;
cin.ignore();
outfile << data << endl; // again write inputted data into the file.
outfile.close(); // close the opened file.
ifstream infile; // open a file in read mode.
infile.open("afile.dat");
cout << "Reading from the file" << endl;
infile >> data;
cout << data << endl; // write the data at the screen.
infile >> data; // again read the data from the file and display it.
cout << data << endl;
infile.close(); // close the opened file.
return 0;
}
Writing to the file
Enter your name: XYZ..
Enter your age: 9
Reading from the file
XYZ..
9
Output
 filebuf accomplishes input and output
operations with files. The streambuf class
does not organize streams for input or
output operations.
 The derived classes of streambuf perform
these operations. It also arranges a
spacefor keeping input data and for sending
output.
 The filebuf class is a derived class
of streambuf that is specialized for buffered
disk file I/O.The buffering is managed entirely
within the iostream Class Library.
 filebufmember functions call the run-time
low-level I/O routines (the functions declared
in <iostream.h>
Filebuf class in iostream
The I/O functions of the classes
istream
and
ostream
invoke the filebuf functions to perform the insertion or
extraction on the streams
The fstreambase acts as a base class for fstream, ifstream,and ofstream.
It holds constant openprototype used in function open() and close() as a member.
The fstream:
It allows both simultaneous input and output operations on a filebuf.
The member function of the base classes istream and ostream starts the input and output.
The ofstream:
This class is derived from fstreambase and ostream classes. It can access the member
functions such as
put() , write() ,display() and It allows output operations and provides the member function
with thedefault output mode.
The ifstream:
This class is derived from fstreambase and istream by multiple inheritance. It can access
the member functions such as get(), getline() , and read()
It allows input operations function with the default input mode.
Program of class student having data member having rollno,name,address.
Accept And Display data for one object
#include<iostream.h> //stream header file and its library is used
#include<conio.h>
class student //class as student is declared.
{
Int roll; variables initialized
Char name[20];
Public: //Access specified as public.
Void accept() // “istream “ is used to accept data from user.
{
Cout<<“n Enter the Name Of student:-”; // cout operator is used to display on screen
Cin>>name; // cin operator is used to stored vale on disk,
Cout<<“n Enter the roll no of student:-”;
Cin >>roll;
}
Void display()
{
Cout<<“n Name of Student :-”<< name; // cout operator is used to display on screen
Cout<<“n Roll No Of Student:-”<<roll; // cout operator is used to display on screen
}
“<<“ & “>>” operator are used for
insertion and extraction of data from
file .
Bottom
Up
Approach
Void display()
{
Cout<<“n Name of Student :-”<< name; // cout operator is used to display on screen
Cout<<“n Roll No Of Student:-”<<roll; // cout operator is used to display on screen
}
};
Void main()
{
Student s1
S1.accept();
S1.display();
Getch();
}
Bottom
Up
Approach
Output
EnterThe Name Of Student:- PPT
EnterThe Roll No:- 001
Name Of The Student Is:- PPT
Roll No :-001
Thank You…..

More Related Content

What's hot

What's hot (20)

Basic concept of OOP's
Basic concept of OOP'sBasic concept of OOP's
Basic concept of OOP's
 
Function in C
Function in CFunction in C
Function in C
 
file handling c++
file handling c++file handling c++
file handling c++
 
File in C language
File in C languageFile in C language
File in C language
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Structure in C
Structure in CStructure in C
Structure in C
 
Access specifiers (Public Private Protected) C++
Access specifiers (Public Private  Protected) C++Access specifiers (Public Private  Protected) C++
Access specifiers (Public Private Protected) C++
 
File Handling in C++
File Handling in C++File Handling in C++
File Handling in C++
 
Files in c++
Files in c++Files in c++
Files in c++
 
File handling in C++
File handling in C++File handling in C++
File handling in C++
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++
 
friend function(c++)
friend function(c++)friend function(c++)
friend function(c++)
 
C Structures and Unions
C Structures and UnionsC Structures and Unions
C Structures and Unions
 
Union in C programming
Union in C programmingUnion in C programming
Union in C programming
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
structure and union
structure and unionstructure and union
structure and union
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
 
Union in c language
Union  in c languageUnion  in c language
Union in c language
 

Viewers also liked (20)

cpp input & output system basics
cpp input & output system basicscpp input & output system basics
cpp input & output system basics
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ ppt
 
File Handling In C++
File Handling In C++File Handling In C++
File Handling In C++
 
C++ io manipulation
C++ io manipulationC++ io manipulation
C++ io manipulation
 
2CPP17 - File IO
2CPP17 - File IO2CPP17 - File IO
2CPP17 - File IO
 
Managing console input and output
Managing console input and outputManaging console input and output
Managing console input and output
 
C++ classes
C++ classesC++ classes
C++ classes
 
C++ Pointers
C++ PointersC++ Pointers
C++ Pointers
 
Unit 6 pointers
Unit 6   pointersUnit 6   pointers
Unit 6 pointers
 
Chap 12(files)
Chap 12(files)Chap 12(files)
Chap 12(files)
 
Union In language C
Union In language CUnion In language C
Union In language C
 
working file handling in cpp overview
working file handling in cpp overviewworking file handling in cpp overview
working file handling in cpp overview
 
File Handling In C++(OOPs))
File Handling In C++(OOPs))File Handling In C++(OOPs))
File Handling In C++(OOPs))
 
Linked list
Linked listLinked list
Linked list
 
Input output streams
Input output streamsInput output streams
Input output streams
 
Variables and data types in C++
Variables and data types in C++Variables and data types in C++
Variables and data types in C++
 
A presentation on types of network
A presentation on types of networkA presentation on types of network
A presentation on types of network
 
Overloading of io stream operators
Overloading of io stream operatorsOverloading of io stream operators
Overloading of io stream operators
 
C++ L01-Variables
C++ L01-VariablesC++ L01-Variables
C++ L01-Variables
 
Formatted input and output
Formatted input and outputFormatted input and output
Formatted input and output
 

Similar to Stream classes in C++

basics of file handling
basics of file handlingbasics of file handling
basics of file handlingpinkpreet_kaur
 
Basics of file handling
Basics of file handlingBasics of file handling
Basics of file handlingpinkpreet_kaur
 
File handling in_c
File handling in_cFile handling in_c
File handling in_csanya6900
 
File management in C++
File management in C++File management in C++
File management in C++apoorvaverma33
 
Managing console i/o operation,working with files
Managing console i/o operation,working with filesManaging console i/o operation,working with files
Managing console i/o operation,working with filesramya marichamy
 
Managing,working with files
Managing,working with filesManaging,working with files
Managing,working with fileskirupasuchi1996
 
Files in C++.pdf is the notes of cpp for reference
Files in C++.pdf is the notes of cpp for referenceFiles in C++.pdf is the notes of cpp for reference
Files in C++.pdf is the notes of cpp for referenceanuvayalil5525
 
streams and files
 streams and files streams and files
streams and filesMariam Butt
 
Data file handling
Data file handlingData file handling
Data file handlingTAlha MAlik
 
Input File dalam C++
Input File dalam C++Input File dalam C++
Input File dalam C++Teguh Nugraha
 
Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01Rex Joe
 
Input output files in java
Input output files in javaInput output files in java
Input output files in javaKavitha713564
 
file management functions
file management functionsfile management functions
file management functionsvaani pathak
 
Chpater29 operation-on-file
Chpater29 operation-on-fileChpater29 operation-on-file
Chpater29 operation-on-fileDeepak Singh
 
C_and_C++_notes.pdf
C_and_C++_notes.pdfC_and_C++_notes.pdf
C_and_C++_notes.pdfTigabu Yaya
 

Similar to Stream classes in C++ (20)

basics of file handling
basics of file handlingbasics of file handling
basics of file handling
 
Basics of file handling
Basics of file handlingBasics of file handling
Basics of file handling
 
File handling in_c
File handling in_cFile handling in_c
File handling in_c
 
File management in C++
File management in C++File management in C++
File management in C++
 
Managing console i/o operation,working with files
Managing console i/o operation,working with filesManaging console i/o operation,working with files
Managing console i/o operation,working with files
 
Managing,working with files
Managing,working with filesManaging,working with files
Managing,working with files
 
Files in C++.pdf is the notes of cpp for reference
Files in C++.pdf is the notes of cpp for referenceFiles in C++.pdf is the notes of cpp for reference
Files in C++.pdf is the notes of cpp for reference
 
File in cpp 2016
File in cpp 2016 File in cpp 2016
File in cpp 2016
 
Streams and Files
Streams and FilesStreams and Files
Streams and Files
 
streams and files
 streams and files streams and files
streams and files
 
Data file handling
Data file handlingData file handling
Data file handling
 
Input File dalam C++
Input File dalam C++Input File dalam C++
Input File dalam C++
 
Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01
 
File handling in cpp
File handling in cppFile handling in cpp
File handling in cpp
 
Chapter4.pptx
Chapter4.pptxChapter4.pptx
Chapter4.pptx
 
working with files
working with filesworking with files
working with files
 
Input output files in java
Input output files in javaInput output files in java
Input output files in java
 
file management functions
file management functionsfile management functions
file management functions
 
Chpater29 operation-on-file
Chpater29 operation-on-fileChpater29 operation-on-file
Chpater29 operation-on-file
 
C_and_C++_notes.pdf
C_and_C++_notes.pdfC_and_C++_notes.pdf
C_and_C++_notes.pdf
 

Recently uploaded

Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptxVinzoCenzo
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsJean Silva
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesVictoriaMetrics
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
SoftTeco - Software Development Company Profile
SoftTeco - Software Development Company ProfileSoftTeco - Software Development Company Profile
SoftTeco - Software Development Company Profileakrivarotava
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...Bert Jan Schrijver
 
Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024Anthony Dahanne
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITmanoharjgpsolutions
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024VictoriaMetrics
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slidesvaideheekore1
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?Alexandre Beguel
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogueitservices996
 

Recently uploaded (20)

Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptx
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero results
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 Updates
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
SoftTeco - Software Development Company Profile
SoftTeco - Software Development Company ProfileSoftTeco - Software Development Company Profile
SoftTeco - Software Development Company Profile
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
 
Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh IT
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slides
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogue
 

Stream classes in C++

  • 2. What Is C++? ▪ C++, as the name suggests, is a superset of C. ▪ C++ can run most of C code while C cannot run C++ code. ▪ C follows the Procedural Programming Language(POP) ▪ while C++ is a language(procedural as well as object oriented) ▪ In C the data is not secured while in C++ data is secured(hidden) . ▪ Encapsulation OF Data Is Done In C++ ▪ In C Importance is given on doingThings(Algorithm) While In C++ importance are given on Data (Object). ▪ C uses the top-down approach while C++ uses the bottom-up approach.
  • 3. What Is Stream? What is its needs in c++? A stream is nothing but a flow of data. In the object-oriented programming, the streams are controlled using the classes.The operations with the files mainly consist of two types. They are read and write. C++ provides various classes, to perform these operations. The ios class is the base class. All other classes are derived from the ios class.These classes contain several member functions that perform input and output operations.
  • 4. Different streams are used to represent different kinds of data flow. Each stream is associated with a particular class, which contains member functions and definitions for dealing with that particular kind of data flow. The stream that supplies data to the program in known as an input stream. It reads the data from the file and hands it over to the program. The stream that receives data from the program is known as an output stream. It writes the received data to the file The following Figure illustratesThis.
  • 5. The Istream and ostream classes control input and output functions, respectively. The ios is the base class of these two classes. The member functions of these classes handle formatted and unformatted operations. ios Istream Used for INPUT function Ostream Used for Output Function
  • 6. File Class Hierarchy ios istream ostream iostream ifstream fstream ofstream iostream.h fstream.h Input Output File I/O Multiple inheritanceBase Class steambuf filebuf
  • 7. Header file Brief description <iostream> Provide basic information required for all stream I/O operation such as cin, cout, cerr and clog correspond to standard input stream, standard output stream, and standard unbuffered and buffered error streams respectively. <iomanip> Contains information useful for performing formatted I/O with parameterized stream manipulation. <fstream> Contains information for user controlled file processing operations. <strstream> Contains information for performing in-memory formatting or in-core formatting. This resembles file processing, but the I/O operation is performed to and from character arrays rather than files. <stdiostrem> Contains information for program that mixes the C and C++ styles of I/O. iostream Library
  • 8. DataType Description ofstream This data type represents the output file stream and is used to create files and to write information to files. ifstream This data type represents the input file stream and is used to read information from files. fstream This data type represents the file stream generally, and has the capabilities of both ofstream and ifstream which means it can create files, write information to files, and read information from files. To perform file processing in c++, header files <iostream> and <fstream> must be included in your c++ source file. DataTypes In Ostream class This data types requires another standard C++ library called fstream, which defines three new data types:
  • 9. Mode Flag Description ios::app Append mode. All output to that file to be appended to the end. ios::ate Open a file for output and move the read/write control to the end of the file. ios::in Open a file for reading. ios::out Open a file for writing. ios::trunc If the file already exists, its contents will be truncated before opening the file. Mode Flag Of iostream Opening a File: A file must be opened before you can read from it or write to it. Either the ofstream or fstream object may be used to open a file for writing And ifstream object is used to open a file for reading purpose only. void open(const char *filename, ios::openmode mode);
  • 10. Closing a File When a C++ program terminates it automatically closes flushes all the streams, release all the allocated memory and close all the opened files. But it is always a good practice that a programmer should close all the opened files before program termination. Following is the standard syntax for close() function, which is a member of fstream, ifstream, and ofstream objects. void close();
  • 11. Operators Brief description cin Object of istream class, connected to the standard input device, normally the keyboard. cout Object of ostream class, connected to standard output device, normally the display/screen. cerr Object of the ostream class connected to standard error device. This is unbuffered output, so each insertion to cerr causes its output to appear immediately. clog Same as cerr but outputs to clog are buffered. Writing to a File: The left shift operator (<<) is overloaded to designate stream output and is called stream insertion operator. write information to a file from your program using the stream insertion operator (<<) just as you use that operator to output information to the screen.The only difference is that you use an of stream or fstream object instead of the cout object. Reading from a File: The right shift operator (>>) is overloaded to designate stream input and is called stream extraction operator. You read information from a file into your program using the stream extraction operator (>>) just as you use that operator to input information from the keyboard.The only difference is that you use an Ifstream or Fstream object instead of the Cin object.
  • 12. Read &Write Example:- // string output using << #include <iostream> void main() { cout<<"Welcome to C++ I/O module!!!"<<endl; cout<<"Welcome to "; cout<<"C++ module 18"<<endl; // endl is end line stream manipulator }  Stream output program example:- Output:
  • 13.  Stream input program example:- #include <iostream.h> void main() { int p, q, r; cout << "Enter 3 integers separated by space: n"; cin>>p>>q>>r; // the >> operator skips whitespace characters cout<<"Sum of the "<<p<<","<<q<<" and "<<r<<" is = "<<(p+q+r)<<endl; } Output:
  • 14. From File Read &Write Example using fstream class #include <fstream> #include <iostream> using namespace std; int main () { char data[100]; ofstream outfile; outfile.open("afile.dat"); // open a file in write mode. cout << "Writing to the file" << endl; cout << "Enter your name: "; cin.getline(data, 100); outfile << data << endl; cout << "Enter your age: "; // write inputted data into the file. cin >> data; cin.ignore(); outfile << data << endl; // again write inputted data into the file. outfile.close(); // close the opened file.
  • 15. ifstream infile; // open a file in read mode. infile.open("afile.dat"); cout << "Reading from the file" << endl; infile >> data; cout << data << endl; // write the data at the screen. infile >> data; // again read the data from the file and display it. cout << data << endl; infile.close(); // close the opened file. return 0; }
  • 16. Writing to the file Enter your name: XYZ.. Enter your age: 9 Reading from the file XYZ.. 9 Output
  • 17.  filebuf accomplishes input and output operations with files. The streambuf class does not organize streams for input or output operations.  The derived classes of streambuf perform these operations. It also arranges a spacefor keeping input data and for sending output.  The filebuf class is a derived class of streambuf that is specialized for buffered disk file I/O.The buffering is managed entirely within the iostream Class Library.  filebufmember functions call the run-time low-level I/O routines (the functions declared in <iostream.h> Filebuf class in iostream
  • 18. The I/O functions of the classes istream and ostream invoke the filebuf functions to perform the insertion or extraction on the streams The fstreambase acts as a base class for fstream, ifstream,and ofstream. It holds constant openprototype used in function open() and close() as a member.
  • 19. The fstream: It allows both simultaneous input and output operations on a filebuf. The member function of the base classes istream and ostream starts the input and output. The ofstream: This class is derived from fstreambase and ostream classes. It can access the member functions such as put() , write() ,display() and It allows output operations and provides the member function with thedefault output mode. The ifstream: This class is derived from fstreambase and istream by multiple inheritance. It can access the member functions such as get(), getline() , and read() It allows input operations function with the default input mode.
  • 20. Program of class student having data member having rollno,name,address. Accept And Display data for one object #include<iostream.h> //stream header file and its library is used #include<conio.h> class student //class as student is declared. { Int roll; variables initialized Char name[20]; Public: //Access specified as public. Void accept() // “istream “ is used to accept data from user. { Cout<<“n Enter the Name Of student:-”; // cout operator is used to display on screen Cin>>name; // cin operator is used to stored vale on disk, Cout<<“n Enter the roll no of student:-”; Cin >>roll; } Void display() { Cout<<“n Name of Student :-”<< name; // cout operator is used to display on screen Cout<<“n Roll No Of Student:-”<<roll; // cout operator is used to display on screen } “<<“ & “>>” operator are used for insertion and extraction of data from file . Bottom Up Approach
  • 21. Void display() { Cout<<“n Name of Student :-”<< name; // cout operator is used to display on screen Cout<<“n Roll No Of Student:-”<<roll; // cout operator is used to display on screen } }; Void main() { Student s1 S1.accept(); S1.display(); Getch(); } Bottom Up Approach Output EnterThe Name Of Student:- PPT EnterThe Roll No:- 001 Name Of The Student Is:- PPT Roll No :-001