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 (20)

FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Templates in c++
Templates in c++Templates in c++
Templates in c++
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Types of Statements in Python Programming Language
Types of Statements in Python Programming LanguageTypes of Statements in Python Programming Language
Types of Statements in Python Programming Language
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
 
functions of C++
functions of C++functions of C++
functions of C++
 
Characteristics of OOPS
Characteristics of OOPS Characteristics of OOPS
Characteristics of OOPS
 
Constructors and Destructor in C++
Constructors and Destructor in C++Constructors and Destructor in C++
Constructors and Destructor in C++
 
File in C language
File in C languageFile in C language
File in C language
 
File handling in C++
File handling in C++File handling in C++
File handling in C++
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Java(Polymorphism)
Java(Polymorphism)Java(Polymorphism)
Java(Polymorphism)
 
Recursion in C++
Recursion in C++Recursion in C++
Recursion in C++
 
Files in c++
Files in c++Files in c++
Files in c++
 
Chapter 07 inheritance
Chapter 07 inheritanceChapter 07 inheritance
Chapter 07 inheritance
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
 

Viewers also liked (20)

cpp input & output system basics
cpp input & output system basicscpp input & output system basics
cpp input & output system basics
 
file handling c++
file handling c++file handling c++
file handling c++
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++
 
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
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).ppt
 
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
 

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

Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfryanfarris8
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 

Recently uploaded (20)

Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 

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