SlideShare a Scribd company logo
1 of 33
M.SUJITHA,M.SC.,
N.S College, Theni.
C++ STREAM CLASSES
Ios:
It contains basic facilities that are used by all other
input and output classes.
Istream:
It inherites the properties of ios and it declares input
functions such as get(),getline() and read().
Ostream:
It inherites the properties of ios and it declares
output functions such as put() and write().
Iostream:
It inherites the properties of ios stream and ostream.
Streambuf:
It provides an interface to physical devices through
buffers.
The features that supports to format the console
I/O operations are:
ā—¦ Ios class functions and flags
ā—¦ Manipulators
ā—¦ User-defined output functions
IOS CLASS FUNCTIONS AND FLAGS:
It consists of large number of member functions
that is used to format the output in number of ways.
ļ½ MANIPULATORS:
These are the special functions that are
included in the I/O statements to format the
parameters of a stream.
ļ½ DEFINING FIELD WIDTH:
ā—¦ It is used to define the width of the field.
ā—¦ Can be defined using width();
ļƒ˜SETTING PRECISION:
It is used to specify the to be displayed after the
decimal point.
ļ¶FILLING AND PADDING:
ļ‚§ It is used to print the values using the larger field
widths.
ļ‚§ It can be declared by,
cout.fill();
#include <iostream>
using namespace std;
int main()
{
int item[4] ={ 10,8,12,15};
int cost[4]={75,100,60,99};
cout.width(5);
cout<<ā€Itemsā€;
cout.width(8);
cout<<ā€Costā€;
cout.width(15);
cout<<ā€Total Valueā€<<ā€nā€;
int sum=0;
for(int i=0;i<4 ;i++)
{
cout.width(5);
cout<<items[i];
cout.width(8);
cout<<cost[i];
int value = items[i] * cost[i];
cout.width(15);
cout<<value<<ā€nā€;
sum= sum + value;
}
cout<<ā€n Grand total = ā€œ;
cout.width(2);
cout<<sum<<ā€nā€;
return 0;
}
OUTPUT:
ITEMS COST TOTAL VALUE
10 75 750
8 100 800
12 60 720
15 99 1485
Grand total =3755
It is used for defining the input and output in
various forms.
Overloaded Operators >> and <<:
ā€¢ It is used to give the I/O
ā€¢ The >> is overloaded in istream class
ā€¢ The << is overloaded in ostream class
Ex:
cin>>item1>>item2;
put() and get() Functions:
ā—¦ It is used for the input and output .
ā—¦ Put(c) is used to give the input
ā—¦ Get(c) is used to get the output
EXAMPLE:
#include <iostream>
using namespace std;
int main()
{
int count=0;
char c;
cout<<ā€INPUT TEXT nā€;
cin.get( c );
while ( c 1=ā€™nā€™ )
while ( c 1=ā€™nā€™ )
{
cout.put( c);
count++;
cin.get( c );
}
cout<< ā€œn Number of characters =ā€ <<count <<ā€nā€;
return 0;
}
OUTPUT:
Object oriented programming
Number of characters=27
Getline() and write() Functions:
ā€¢ The getline() function reads a whole line of the
text and ends with a newline character.
ā€¢ This function can be invoked by,
cin.getline (line,size);
ā€¢ The writeline() function reads a whole line of the
text and displays an entire line.
ā€¢ This function can be invoked by,
cout.write (line,size);
EXAMPLE:
#include <iostream>
using namespace std;
int main()
{
int size=20;
char city[20];
cout<<ā€enter city name:n ā€œ;
cin>>city;
cout<<ā€city name:ā€<<city<<ā€nnā€;
cout<<ā€enter city name again: nā€;
cin.getline(city,size);
cout<<ā€city name now:ā€<<city<<ā€nnā€;
cout<<ā€enter another city name: nā€;
cin.getline(city,size);
cout <<ā€New city name:ā€<<city<<ā€nnā€™;
return 0;
}
OUTPUT:
first run
Enter city name:
Delhi
Enter city name again:
City name now:
Enter another city name:
Chennai
New city name:
Chennai
ļ½ The header file iomanip provides a set of functions
called manipulators which can be used to manipulate
the output formats.
ļ½ They provide the same features as that of the ios
member function and flag.
ļ½ Two or more manipulators can be,
Cout<<manip1<<manip1<<manip<<item;
Cout<<manip1<<item1<<manip2<<item2;
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
cout.setf(ios::showpoint);
cout<<setw(5)<<ā€nā€<<setw(15)<<ā€inverse of
nā€<<setw(15)<<ā€sum of termsā€;
double term,sum=0;
for (int n=1;n<=10;n++)
{
term=1.0/float(n);
sum=sum + term;
cout<<setw(5)<<n<<setw(14)<<setprecision(4)<<setiosflags(ios::ss
scientific)<<term<<setw(13)<<resetioflags(ios::scientific<<sum<
<endl;
}
return 0;
}
ļ½ The large amount of Data can be handled using some
devices such as floppy disk or hard disk to store those
datas.
ļ½ These datas are stored in these devices called FILES.
ļ½ The Programs can be designed to perform the read and
write operations on those files.
ļ½ Kinds of Data Communication:
ā—¦ Data Transfer between the console unit and the
program.
ā—¦ Data Transfer between the program and a Diskfile.
FILEBUF:
It is used to set the file buffers to read and write.
FSTREAMBASE:
It provides operations common to the file streams.
IFSTREAM:
It provides input operations.
OFSTREAM:
It provides output operations.
FSTREAM:
It provides support for both input and output
operations.
ļ½ The I/O system contains a set of classes that define
the file handling methods.
ļ½ These includes ifstream, ofstream and fstream.
ļ½ These classes are derived from fstreambase and from
the corresponding iostream class.
ļ½ These classes are designed to manage the Disk files,
which are declared in fstream and we should include
any program in these files.
ļƒ˜ A file stream can be declared using the classes
ifstream, ofstream and fstream that are contained in
the Header file fstream.
ļƒ˜ A file can be Opened into two ways:
ļƒ˜Using the Constructor function of the class
ļƒ˜Using the Member function open() of the class
OPENING FILES USING Open():
ļƒ˜ The function open() can be used to open multiple
files that use the same stream object.
file-stream-class stream-object;
stream-object.open (ā€œfile nameā€);
#include<iostream.h>
#include<fstream.h>
int main()
{
ofstream fout;
fout.open(ā€œCountry namesā€);
fout<<ā€œUniited States Of Americanā€;
fout<<ā€œUnited Kingdomnā€;
fout.close();
return 0;
}
OUTPUT:
Country names
United States Of America
United Kingdom
This condition is necessary for preventing data
from the file. This condition is
MORE ABOUT OPEN( ): FILE MODES
ā€¢ The ifstream and ofstream is used to create
the new files.
ā€¢ The function open( ) is used to open a new
stream.
object. open(ā€œfile nameā€,mode);
Each file has two associated pointers known
as File pointers.
DEFAULT ACTIONS:
When we open a file in read-only-mode
,these input pointer is automatically set at the
beginning.
FUNCTIONS FOR MANIPULATION OF FILE POINTERS:
ļ‚§ seekg()-Moves a pointer to specified location
ļ‚§ seekp()-Moves put pointer to a specified location
ļ‚§ tellg()-Gives the current position of the get pointer
ļ‚§ tellp()-Gives the current position of the put pointer
It supports a number of member function for
performing the input/output operations on files.
Put() and get() Functions:
ā—¦ It is used to handle single character at a time.
ā—¦ The function put() writes a single character to the
associated stream.
ā—¦ The function get() reads a single character to the
associated stream.
Write() and read() Functions:
It is used to read and write the blocks in the binary
data.
ļ½ It is used to maintain the routine task in the data file.
ļ½ The updation can be done in:
ā—¦ Displaying the contents of a file
ā—¦ Modifying an existing item
ā—¦ Adding a new file
ā—¦ Deleting an existing file
ļ½ The reading and writing files may not be true
always.
ā—¦ A file which we are attempting to open for reading
does not exist.
ā—¦ The file name used for a new file may already exist.
ā—¦ We may use an invalid file name.
ā—¦ There may not be any space in the disk for storing
more data.
ā—¦ We may attempt to perform an operation when the
file is not opened for that purpose.
ļ½ This feature facilities the supply of arguments to the
main() function.
ļ½ These arguments are supplied at the time of invoking
the program.
ā—¦ C> exam data results
ā—¦ Exam is the name of the file containing the program
to be executed ,data and results are the filenames
passed to the program as command-line arguments.
THANKYOU!!!

More Related Content

What's hot

Data file handling in python binary & csv files
Data file handling in python binary & csv filesData file handling in python binary & csv files
Data file handling in python binary & csv fileskeeeerty
Ā 
08. handling file streams
08. handling file streams08. handling file streams
08. handling file streamsHaresh Jaiswal
Ā 
File handling in C++
File handling in C++File handling in C++
File handling in C++Hitesh Kumar
Ā 
Filehandlinging cp2
Filehandlinging cp2Filehandlinging cp2
Filehandlinging cp2Tanmay Baranwal
Ā 
Pipes and filters
Pipes and filtersPipes and filters
Pipes and filtersbhatvijetha
Ā 
Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01Rex Joe
Ā 
file handling, dynamic memory allocation
file handling, dynamic memory allocationfile handling, dynamic memory allocation
file handling, dynamic memory allocationindra Kishor
Ā 
Functions in python
Functions in pythonFunctions in python
Functions in pythonSantosh Verma
Ā 
basics of file handling
basics of file handlingbasics of file handling
basics of file handlingpinkpreet_kaur
Ā 
Format String
Format StringFormat String
Format StringWei-Bo Chen
Ā 
Complete Guide for Linux shell programming
Complete Guide for Linux shell programmingComplete Guide for Linux shell programming
Complete Guide for Linux shell programmingsudhir singh yadav
Ā 
Data file handling
Data file handlingData file handling
Data file handlingSaurabh Patel
Ā 
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
Ā 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File HandlingSunil OS
Ā 

What's hot (20)

Files in c++
Files in c++Files in c++
Files in c++
Ā 
Data file handling in python binary & csv files
Data file handling in python binary & csv filesData file handling in python binary & csv files
Data file handling in python binary & csv files
Ā 
08. handling file streams
08. handling file streams08. handling file streams
08. handling file streams
Ā 
File handling in C++
File handling in C++File handling in C++
File handling in C++
Ā 
Filehandlinging cp2
Filehandlinging cp2Filehandlinging cp2
Filehandlinging cp2
Ā 
Pipes and filters
Pipes and filtersPipes and filters
Pipes and filters
Ā 
Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01
Ā 
file handling, dynamic memory allocation
file handling, dynamic memory allocationfile handling, dynamic memory allocation
file handling, dynamic memory allocation
Ā 
Functions in python
Functions in pythonFunctions in python
Functions in python
Ā 
basics of file handling
basics of file handlingbasics of file handling
basics of file handling
Ā 
Format String
Format StringFormat String
Format String
Ā 
Complete Guide for Linux shell programming
Complete Guide for Linux shell programmingComplete Guide for Linux shell programming
Complete Guide for Linux shell programming
Ā 
File Handling in C++
File Handling in C++File Handling in C++
File Handling in C++
Ā 
Data file handling
Data file handlingData file handling
Data file handling
Ā 
Java File I/O
Java File I/OJava File I/O
Java File I/O
Ā 
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++
Ā 
Filehadnling
FilehadnlingFilehadnling
Filehadnling
Ā 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File Handling
Ā 
Python - Lecture 11
Python - Lecture 11Python - Lecture 11
Python - Lecture 11
Ā 

Similar to C++ STREAM CLASSES: INPUT/OUTPUT WITH FILES AND STREAMS

Managing console of I/o operations & working with files
Managing console of I/o operations & working with filesManaging console of I/o operations & working with files
Managing console of I/o operations & working with fileslalithambiga kamaraj
Ā 
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
Ā 
File handling in_c
File handling in_cFile handling in_c
File handling in_csanya6900
Ā 
Basics of file handling
Basics of file handlingBasics of file handling
Basics of file handlingpinkpreet_kaur
Ā 
C_and_C++_notes.pdf
C_and_C++_notes.pdfC_and_C++_notes.pdf
C_and_C++_notes.pdfTigabu Yaya
Ā 
cpp-file-handling
cpp-file-handlingcpp-file-handling
cpp-file-handlingzohaib ali ali
Ā 
Basics of files and its functions with example
Basics of files and its functions with exampleBasics of files and its functions with example
Basics of files and its functions with exampleSunil Patel
Ā 
working with files
working with filesworking with files
working with filesSangeethaSasi1
Ā 
programming language in c&c++
programming language in c&c++programming language in c&c++
programming language in c&c++Haripritha
Ā 
Lec 47.48 - stream-files
Lec 47.48 - stream-filesLec 47.48 - stream-files
Lec 47.48 - stream-filesPrincess Sam
Ā 
working with files
working with filesworking with files
working with filesSangeethaSasi1
Ā 
Managing console input
Managing console inputManaging console input
Managing console inputrajshreemuthiah
Ā 
Chapter28 data-file-handling
Chapter28 data-file-handlingChapter28 data-file-handling
Chapter28 data-file-handlingDeepak Singh
Ā 
Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)Abdullah khawar
Ā 

Similar to C++ STREAM CLASSES: INPUT/OUTPUT WITH FILES AND STREAMS (20)

Managing console of I/o operations & working with files
Managing console of I/o operations & working with filesManaging console of I/o operations & working with files
Managing console of I/o operations & 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
Ā 
streams and files
 streams and files streams and files
streams and files
Ā 
File handling in_c
File handling in_cFile handling in_c
File handling in_c
Ā 
Basics of file handling
Basics of file handlingBasics of file handling
Basics of file handling
Ā 
Files and streams
Files and streamsFiles and streams
Files and streams
Ā 
C_and_C++_notes.pdf
C_and_C++_notes.pdfC_and_C++_notes.pdf
C_and_C++_notes.pdf
Ā 
IOStream.pptx
IOStream.pptxIOStream.pptx
IOStream.pptx
Ā 
cpp-file-handling
cpp-file-handlingcpp-file-handling
cpp-file-handling
Ā 
Cpp file-handling
Cpp file-handlingCpp file-handling
Cpp file-handling
Ā 
Basics of files and its functions with example
Basics of files and its functions with exampleBasics of files and its functions with example
Basics of files and its functions with example
Ā 
working with files
working with filesworking with files
working with files
Ā 
programming language in c&c++
programming language in c&c++programming language in c&c++
programming language in c&c++
Ā 
Lec 47.48 - stream-files
Lec 47.48 - stream-filesLec 47.48 - stream-files
Lec 47.48 - stream-files
Ā 
Java I/O
Java I/OJava I/O
Java I/O
Ā 
working with files
working with filesworking with files
working with files
Ā 
Managing console input
Managing console inputManaging console input
Managing console input
Ā 
C
CC
C
Ā 
Chapter28 data-file-handling
Chapter28 data-file-handlingChapter28 data-file-handling
Chapter28 data-file-handling
Ā 
Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)
Ā 

More from kirupasuchi1996

Rotor machine,subsitution technique
Rotor machine,subsitution techniqueRotor machine,subsitution technique
Rotor machine,subsitution techniquekirupasuchi1996
Ā 
DVI,FRACTAL IMAGE,SUB BAND IMAGE,VIDEO CODING AND WAVELET BASED COMPRESSION
DVI,FRACTAL IMAGE,SUB BAND IMAGE,VIDEO CODING AND WAVELET BASED COMPRESSIONDVI,FRACTAL IMAGE,SUB BAND IMAGE,VIDEO CODING AND WAVELET BASED COMPRESSION
DVI,FRACTAL IMAGE,SUB BAND IMAGE,VIDEO CODING AND WAVELET BASED COMPRESSIONkirupasuchi1996
Ā 
Image compression standards
Image compression standardsImage compression standards
Image compression standardskirupasuchi1996
Ā 
Language and Processors for Requirements Specification
Language and Processors for Requirements SpecificationLanguage and Processors for Requirements Specification
Language and Processors for Requirements Specificationkirupasuchi1996
Ā 
Software Cost Factor
Software Cost FactorSoftware Cost Factor
Software Cost Factorkirupasuchi1996
Ā 
GUI components in Java
GUI components in JavaGUI components in Java
GUI components in Javakirupasuchi1996
Ā 
Designing Techniques in Software Engineering
Designing Techniques in Software EngineeringDesigning Techniques in Software Engineering
Designing Techniques in Software Engineeringkirupasuchi1996
Ā 
Dmppt 180312092027
Dmppt 180312092027Dmppt 180312092027
Dmppt 180312092027kirupasuchi1996
Ā 
Datatransferandmanipulation 180214044522
Datatransferandmanipulation 180214044522Datatransferandmanipulation 180214044522
Datatransferandmanipulation 180214044522kirupasuchi1996
Ā 
Filesharing 180214044607
Filesharing 180214044607Filesharing 180214044607
Filesharing 180214044607kirupasuchi1996
Ā 
B tree-180214044656
B tree-180214044656B tree-180214044656
B tree-180214044656kirupasuchi1996
Ā 

More from kirupasuchi1996 (15)

Rotor machine,subsitution technique
Rotor machine,subsitution techniqueRotor machine,subsitution technique
Rotor machine,subsitution technique
Ā 
rotor machine
rotor machinerotor machine
rotor machine
Ā 
DVI,FRACTAL IMAGE,SUB BAND IMAGE,VIDEO CODING AND WAVELET BASED COMPRESSION
DVI,FRACTAL IMAGE,SUB BAND IMAGE,VIDEO CODING AND WAVELET BASED COMPRESSIONDVI,FRACTAL IMAGE,SUB BAND IMAGE,VIDEO CODING AND WAVELET BASED COMPRESSION
DVI,FRACTAL IMAGE,SUB BAND IMAGE,VIDEO CODING AND WAVELET BASED COMPRESSION
Ā 
Cyper crime
Cyper crimeCyper crime
Cyper crime
Ā 
DS ppt
DS pptDS ppt
DS ppt
Ā 
Image compression standards
Image compression standardsImage compression standards
Image compression standards
Ā 
Language and Processors for Requirements Specification
Language and Processors for Requirements SpecificationLanguage and Processors for Requirements Specification
Language and Processors for Requirements Specification
Ā 
Software Cost Factor
Software Cost FactorSoftware Cost Factor
Software Cost Factor
Ā 
GUI components in Java
GUI components in JavaGUI components in Java
GUI components in Java
Ā 
Designing Techniques in Software Engineering
Designing Techniques in Software EngineeringDesigning Techniques in Software Engineering
Designing Techniques in Software Engineering
Ā 
Dmppt 180312092027
Dmppt 180312092027Dmppt 180312092027
Dmppt 180312092027
Ā 
Datatransferandmanipulation 180214044522
Datatransferandmanipulation 180214044522Datatransferandmanipulation 180214044522
Datatransferandmanipulation 180214044522
Ā 
Filesharing 180214044607
Filesharing 180214044607Filesharing 180214044607
Filesharing 180214044607
Ā 
B tree-180214044656
B tree-180214044656B tree-180214044656
B tree-180214044656
Ā 
Addressingmodes
Addressingmodes Addressingmodes
Addressingmodes
Ā 

Recently uploaded

Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
Ā 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
Ā 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
Ā 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
Ā 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
Ā 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
Ā 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
Ā 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
Ā 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
Ā 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
Ā 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
Ā 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
Ā 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
Ā 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
Ā 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
Ā 
Nellā€™iperspazio con Rocket: il Framework Web di Rust!
Nellā€™iperspazio con Rocket: il Framework Web di Rust!Nellā€™iperspazio con Rocket: il Framework Web di Rust!
Nellā€™iperspazio con Rocket: il Framework Web di Rust!Commit University
Ā 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
Ā 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
Ā 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
Ā 

Recently uploaded (20)

Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
Ā 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Ā 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
Ā 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
Ā 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
Ā 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
Ā 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
Ā 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
Ā 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
Ā 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
Ā 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
Ā 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
Ā 
Hot Sexy call girls in Panjabi Bagh šŸ” 9953056974 šŸ” Delhi escort Service
Hot Sexy call girls in Panjabi Bagh šŸ” 9953056974 šŸ” Delhi escort ServiceHot Sexy call girls in Panjabi Bagh šŸ” 9953056974 šŸ” Delhi escort Service
Hot Sexy call girls in Panjabi Bagh šŸ” 9953056974 šŸ” Delhi escort Service
Ā 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
Ā 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
Ā 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Ā 
Nellā€™iperspazio con Rocket: il Framework Web di Rust!
Nellā€™iperspazio con Rocket: il Framework Web di Rust!Nellā€™iperspazio con Rocket: il Framework Web di Rust!
Nellā€™iperspazio con Rocket: il Framework Web di Rust!
Ā 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
Ā 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
Ā 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
Ā 

C++ STREAM CLASSES: INPUT/OUTPUT WITH FILES AND STREAMS

  • 3. Ios: It contains basic facilities that are used by all other input and output classes. Istream: It inherites the properties of ios and it declares input functions such as get(),getline() and read(). Ostream: It inherites the properties of ios and it declares output functions such as put() and write(). Iostream: It inherites the properties of ios stream and ostream. Streambuf: It provides an interface to physical devices through buffers.
  • 4. The features that supports to format the console I/O operations are: ā—¦ Ios class functions and flags ā—¦ Manipulators ā—¦ User-defined output functions IOS CLASS FUNCTIONS AND FLAGS: It consists of large number of member functions that is used to format the output in number of ways.
  • 5. ļ½ MANIPULATORS: These are the special functions that are included in the I/O statements to format the parameters of a stream. ļ½ DEFINING FIELD WIDTH: ā—¦ It is used to define the width of the field. ā—¦ Can be defined using width(); ļƒ˜SETTING PRECISION: It is used to specify the to be displayed after the decimal point. ļ¶FILLING AND PADDING: ļ‚§ It is used to print the values using the larger field widths. ļ‚§ It can be declared by, cout.fill();
  • 6. #include <iostream> using namespace std; int main() { int item[4] ={ 10,8,12,15}; int cost[4]={75,100,60,99}; cout.width(5); cout<<ā€Itemsā€; cout.width(8); cout<<ā€Costā€;
  • 7. cout.width(15); cout<<ā€Total Valueā€<<ā€nā€; int sum=0; for(int i=0;i<4 ;i++) { cout.width(5); cout<<items[i]; cout.width(8); cout<<cost[i]; int value = items[i] * cost[i]; cout.width(15);
  • 8. cout<<value<<ā€nā€; sum= sum + value; } cout<<ā€n Grand total = ā€œ; cout.width(2); cout<<sum<<ā€nā€; return 0; }
  • 9. OUTPUT: ITEMS COST TOTAL VALUE 10 75 750 8 100 800 12 60 720 15 99 1485 Grand total =3755
  • 10. It is used for defining the input and output in various forms. Overloaded Operators >> and <<: ā€¢ It is used to give the I/O ā€¢ The >> is overloaded in istream class ā€¢ The << is overloaded in ostream class Ex: cin>>item1>>item2;
  • 11. put() and get() Functions: ā—¦ It is used for the input and output . ā—¦ Put(c) is used to give the input ā—¦ Get(c) is used to get the output EXAMPLE: #include <iostream> using namespace std; int main() { int count=0; char c; cout<<ā€INPUT TEXT nā€; cin.get( c ); while ( c 1=ā€™nā€™ )
  • 12. while ( c 1=ā€™nā€™ ) { cout.put( c); count++; cin.get( c ); } cout<< ā€œn Number of characters =ā€ <<count <<ā€nā€; return 0; } OUTPUT: Object oriented programming Number of characters=27
  • 13. Getline() and write() Functions: ā€¢ The getline() function reads a whole line of the text and ends with a newline character. ā€¢ This function can be invoked by, cin.getline (line,size); ā€¢ The writeline() function reads a whole line of the text and displays an entire line. ā€¢ This function can be invoked by, cout.write (line,size);
  • 14. EXAMPLE: #include <iostream> using namespace std; int main() { int size=20; char city[20]; cout<<ā€enter city name:n ā€œ; cin>>city; cout<<ā€city name:ā€<<city<<ā€nnā€; cout<<ā€enter city name again: nā€; cin.getline(city,size);
  • 15. cout<<ā€city name now:ā€<<city<<ā€nnā€; cout<<ā€enter another city name: nā€; cin.getline(city,size); cout <<ā€New city name:ā€<<city<<ā€nnā€™; return 0; }
  • 16. OUTPUT: first run Enter city name: Delhi Enter city name again: City name now: Enter another city name: Chennai New city name: Chennai
  • 17. ļ½ The header file iomanip provides a set of functions called manipulators which can be used to manipulate the output formats. ļ½ They provide the same features as that of the ios member function and flag. ļ½ Two or more manipulators can be, Cout<<manip1<<manip1<<manip<<item; Cout<<manip1<<item1<<manip2<<item2;
  • 18. #include<iostream> #include<iomanip> using namespace std; int main() { cout.setf(ios::showpoint); cout<<setw(5)<<ā€nā€<<setw(15)<<ā€inverse of nā€<<setw(15)<<ā€sum of termsā€; double term,sum=0; for (int n=1;n<=10;n++)
  • 20. ļ½ The large amount of Data can be handled using some devices such as floppy disk or hard disk to store those datas. ļ½ These datas are stored in these devices called FILES. ļ½ The Programs can be designed to perform the read and write operations on those files. ļ½ Kinds of Data Communication: ā—¦ Data Transfer between the console unit and the program. ā—¦ Data Transfer between the program and a Diskfile.
  • 21.
  • 22. FILEBUF: It is used to set the file buffers to read and write. FSTREAMBASE: It provides operations common to the file streams. IFSTREAM: It provides input operations. OFSTREAM: It provides output operations. FSTREAM: It provides support for both input and output operations.
  • 23. ļ½ The I/O system contains a set of classes that define the file handling methods. ļ½ These includes ifstream, ofstream and fstream. ļ½ These classes are derived from fstreambase and from the corresponding iostream class. ļ½ These classes are designed to manage the Disk files, which are declared in fstream and we should include any program in these files.
  • 24. ļƒ˜ A file stream can be declared using the classes ifstream, ofstream and fstream that are contained in the Header file fstream. ļƒ˜ A file can be Opened into two ways: ļƒ˜Using the Constructor function of the class ļƒ˜Using the Member function open() of the class OPENING FILES USING Open(): ļƒ˜ The function open() can be used to open multiple files that use the same stream object. file-stream-class stream-object; stream-object.open (ā€œfile nameā€);
  • 25. #include<iostream.h> #include<fstream.h> int main() { ofstream fout; fout.open(ā€œCountry namesā€); fout<<ā€œUniited States Of Americanā€; fout<<ā€œUnited Kingdomnā€; fout.close(); return 0;
  • 26. } OUTPUT: Country names United States Of America United Kingdom
  • 27. This condition is necessary for preventing data from the file. This condition is MORE ABOUT OPEN( ): FILE MODES ā€¢ The ifstream and ofstream is used to create the new files. ā€¢ The function open( ) is used to open a new stream. object. open(ā€œfile nameā€,mode);
  • 28. Each file has two associated pointers known as File pointers. DEFAULT ACTIONS: When we open a file in read-only-mode ,these input pointer is automatically set at the beginning. FUNCTIONS FOR MANIPULATION OF FILE POINTERS: ļ‚§ seekg()-Moves a pointer to specified location ļ‚§ seekp()-Moves put pointer to a specified location ļ‚§ tellg()-Gives the current position of the get pointer ļ‚§ tellp()-Gives the current position of the put pointer
  • 29. It supports a number of member function for performing the input/output operations on files. Put() and get() Functions: ā—¦ It is used to handle single character at a time. ā—¦ The function put() writes a single character to the associated stream. ā—¦ The function get() reads a single character to the associated stream. Write() and read() Functions: It is used to read and write the blocks in the binary data.
  • 30. ļ½ It is used to maintain the routine task in the data file. ļ½ The updation can be done in: ā—¦ Displaying the contents of a file ā—¦ Modifying an existing item ā—¦ Adding a new file ā—¦ Deleting an existing file
  • 31. ļ½ The reading and writing files may not be true always. ā—¦ A file which we are attempting to open for reading does not exist. ā—¦ The file name used for a new file may already exist. ā—¦ We may use an invalid file name. ā—¦ There may not be any space in the disk for storing more data. ā—¦ We may attempt to perform an operation when the file is not opened for that purpose.
  • 32. ļ½ This feature facilities the supply of arguments to the main() function. ļ½ These arguments are supplied at the time of invoking the program. ā—¦ C> exam data results ā—¦ Exam is the name of the file containing the program to be executed ,data and results are the filenames passed to the program as command-line arguments.