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

Infix prefix postfix
Infix prefix postfixInfix prefix postfix
Infix prefix postfixSelf-Employed
Ā 
Python-02| Input, Output & Import
Python-02| Input, Output & ImportPython-02| Input, Output & Import
Python-02| Input, Output & ImportMohd Sajjad
Ā 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)Ritika Sharma
Ā 
Constructor ppt
Constructor pptConstructor ppt
Constructor pptVinod Kumar
Ā 
My lecture infix-to-postfix
My lecture infix-to-postfixMy lecture infix-to-postfix
My lecture infix-to-postfixSenthil Kumar
Ā 
Presentation on pointer.
Presentation on pointer.Presentation on pointer.
Presentation on pointer.Md. Afif Al Mamun
Ā 
Stack - Data Structure - Notes
Stack - Data Structure - NotesStack - Data Structure - Notes
Stack - Data Structure - NotesOmprakash Chauhan
Ā 
Polish Notation In Data Structure
Polish Notation In Data StructurePolish Notation In Data Structure
Polish Notation In Data StructureMeghaj Mallick
Ā 
Infix to postfix conversion
Infix to postfix conversionInfix to postfix conversion
Infix to postfix conversionThen Murugeshwari
Ā 
Function overloading and overriding
Function overloading and overridingFunction overloading and overriding
Function overloading and overridingRajab Ali
Ā 
Applications of stack
Applications of stackApplications of stack
Applications of stackeShikshak
Ā 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide shareDevashish Kumar
Ā 
Parameter passing to_functions_in_c
Parameter passing to_functions_in_cParameter passing to_functions_in_c
Parameter passing to_functions_in_cForwardBlog Enewzletter
Ā 

What's hot (20)

Infix prefix postfix
Infix prefix postfixInfix prefix postfix
Infix prefix postfix
Ā 
Python-02| Input, Output & Import
Python-02| Input, Output & ImportPython-02| Input, Output & Import
Python-02| Input, Output & Import
Ā 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
Ā 
Python dictionary
Python   dictionaryPython   dictionary
Python dictionary
Ā 
Constructor ppt
Constructor pptConstructor ppt
Constructor ppt
Ā 
Strings
StringsStrings
Strings
Ā 
Managing I/O in c++
Managing I/O in c++Managing I/O in c++
Managing I/O in c++
Ā 
My lecture infix-to-postfix
My lecture infix-to-postfixMy lecture infix-to-postfix
My lecture infix-to-postfix
Ā 
Functions in c++
Functions in c++Functions in c++
Functions in c++
Ā 
Presentation on pointer.
Presentation on pointer.Presentation on pointer.
Presentation on pointer.
Ā 
Stack - Data Structure - Notes
Stack - Data Structure - NotesStack - Data Structure - Notes
Stack - Data Structure - Notes
Ā 
Polish Notation In Data Structure
Polish Notation In Data StructurePolish Notation In Data Structure
Polish Notation In Data Structure
Ā 
Operator.ppt
Operator.pptOperator.ppt
Operator.ppt
Ā 
Infix to postfix conversion
Infix to postfix conversionInfix to postfix conversion
Infix to postfix conversion
Ā 
Function overloading and overriding
Function overloading and overridingFunction overloading and overriding
Function overloading and overriding
Ā 
Rules of Karnaugh Map
Rules of Karnaugh MapRules of Karnaugh Map
Rules of Karnaugh Map
Ā 
Applications of stack
Applications of stackApplications of stack
Applications of stack
Ā 
Python tuple
Python   tuplePython   tuple
Python tuple
Ā 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
Ā 
Parameter passing to_functions_in_c
Parameter passing to_functions_in_cParameter passing to_functions_in_c
Parameter passing to_functions_in_c
Ā 

Similar to Managing console i/o operation,working with files

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
Ā 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++Shyam Gupta
Ā 
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
Ā 
Basics of file handling
Basics of file handlingBasics of file handling
Basics of file handlingpinkpreet_kaur
Ā 
Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01Rex Joe
Ā 
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
Ā 

Similar to Managing console i/o operation,working with files (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
Ā 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++
Ā 
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
Ā 
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
Ā 
Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01
Ā 
Files in c++
Files in c++Files in c++
Files in c++
Ā 
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
Ā 

More from ramya marichamy

NETWORK DEVICE SECURITY NETWORK HARDENING
NETWORK DEVICE SECURITY NETWORK HARDENINGNETWORK DEVICE SECURITY NETWORK HARDENING
NETWORK DEVICE SECURITY NETWORK HARDENINGramya marichamy
Ā 
DIGITAL VIDEO DATA SIZING AND OBJECT BASED ANIMATION
DIGITAL VIDEO DATA SIZING AND OBJECT BASED ANIMATIONDIGITAL VIDEO DATA SIZING AND OBJECT BASED ANIMATION
DIGITAL VIDEO DATA SIZING AND OBJECT BASED ANIMATIONramya marichamy
Ā 
Classical encryption techniques
Classical encryption techniquesClassical encryption techniques
Classical encryption techniquesramya marichamy
Ā 
Servlets api overview
Servlets api overviewServlets api overview
Servlets api overviewramya marichamy
Ā 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquerramya marichamy
Ā 
Region based segmentation
Region based segmentationRegion based segmentation
Region based segmentationramya marichamy
Ā 
Mining single dimensional boolean association rules from transactional
Mining single dimensional boolean association rules from transactionalMining single dimensional boolean association rules from transactional
Mining single dimensional boolean association rules from transactionalramya marichamy
Ā 
Architecture of data mining system
Architecture of data mining systemArchitecture of data mining system
Architecture of data mining systemramya marichamy
Ā 
Arithmetic & Logic Unit
Arithmetic & Logic UnitArithmetic & Logic Unit
Arithmetic & Logic Unitramya marichamy
Ā 
SHADOW PAGING and BUFFER MANAGEMENT
SHADOW PAGING and BUFFER MANAGEMENTSHADOW PAGING and BUFFER MANAGEMENT
SHADOW PAGING and BUFFER MANAGEMENTramya marichamy
Ā 
pointer, virtual function and polymorphism
pointer, virtual function and polymorphismpointer, virtual function and polymorphism
pointer, virtual function and polymorphismramya marichamy
Ā 
Operator overloading
Operator overloadingOperator overloading
Operator overloadingramya marichamy
Ā 
microcomputer architecture - Arithmetic instruction
microcomputer architecture - Arithmetic instructionmicrocomputer architecture - Arithmetic instruction
microcomputer architecture - Arithmetic instructionramya marichamy
Ā 

More from ramya marichamy (19)

NETWORK DEVICE SECURITY NETWORK HARDENING
NETWORK DEVICE SECURITY NETWORK HARDENINGNETWORK DEVICE SECURITY NETWORK HARDENING
NETWORK DEVICE SECURITY NETWORK HARDENING
Ā 
DIGITAL VIDEO DATA SIZING AND OBJECT BASED ANIMATION
DIGITAL VIDEO DATA SIZING AND OBJECT BASED ANIMATIONDIGITAL VIDEO DATA SIZING AND OBJECT BASED ANIMATION
DIGITAL VIDEO DATA SIZING AND OBJECT BASED ANIMATION
Ā 
Image processing
Image processingImage processing
Image processing
Ā 
Classical encryption techniques
Classical encryption techniquesClassical encryption techniques
Classical encryption techniques
Ā 
Servlets api overview
Servlets api overviewServlets api overview
Servlets api overview
Ā 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
Ā 
Region based segmentation
Region based segmentationRegion based segmentation
Region based segmentation
Ā 
Design notation
Design notationDesign notation
Design notation
Ā 
Mining single dimensional boolean association rules from transactional
Mining single dimensional boolean association rules from transactionalMining single dimensional boolean association rules from transactional
Mining single dimensional boolean association rules from transactional
Ā 
Architecture of data mining system
Architecture of data mining systemArchitecture of data mining system
Architecture of data mining system
Ā 
segmentation
segmentationsegmentation
segmentation
Ā 
File Management
File ManagementFile Management
File Management
Ā 
Arithmetic & Logic Unit
Arithmetic & Logic UnitArithmetic & Logic Unit
Arithmetic & Logic Unit
Ā 
SHADOW PAGING and BUFFER MANAGEMENT
SHADOW PAGING and BUFFER MANAGEMENTSHADOW PAGING and BUFFER MANAGEMENT
SHADOW PAGING and BUFFER MANAGEMENT
Ā 
B+ tree
B+ treeB+ tree
B+ tree
Ā 
pointer, virtual function and polymorphism
pointer, virtual function and polymorphismpointer, virtual function and polymorphism
pointer, virtual function and polymorphism
Ā 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
Ā 
microcomputer architecture - Arithmetic instruction
microcomputer architecture - Arithmetic instructionmicrocomputer architecture - Arithmetic instruction
microcomputer architecture - Arithmetic instruction
Ā 
High speed lan
High speed lanHigh speed lan
High speed lan
Ā 

Recently uploaded

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
Ā 
Hį»ŒC Tį»T TIįŗ¾NG ANH 11 THEO CHĘÆĘ NG TRƌNH GLOBAL SUCCESS ĐƁP ƁN CHI TIįŗ¾T - Cįŗ¢ NĂ...
Hį»ŒC Tį»T TIįŗ¾NG ANH 11 THEO CHĘÆĘ NG TRƌNH GLOBAL SUCCESS ĐƁP ƁN CHI TIįŗ¾T - Cįŗ¢ NĂ...Hį»ŒC Tį»T TIįŗ¾NG ANH 11 THEO CHĘÆĘ NG TRƌNH GLOBAL SUCCESS ĐƁP ƁN CHI TIįŗ¾T - Cįŗ¢ NĂ...
Hį»ŒC Tį»T TIįŗ¾NG ANH 11 THEO CHĘÆĘ NG TRƌNH GLOBAL SUCCESS ĐƁP ƁN CHI TIįŗ¾T - Cįŗ¢ NĂ...Nguyen Thanh Tu Collection
Ā 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
Ā 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
Ā 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
Ā 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
Ā 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
Ā 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
Ā 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
Ā 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
Ā 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
Ā 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
Ā 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
Ā 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
Ā 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
Ā 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
Ā 

Recently uploaded (20)

Model Call Girl in Tilak Nagar Delhi reach out to us at šŸ”9953056974šŸ”
Model Call Girl in Tilak Nagar Delhi reach out to us at šŸ”9953056974šŸ”Model Call Girl in Tilak Nagar Delhi reach out to us at šŸ”9953056974šŸ”
Model Call Girl in Tilak Nagar Delhi reach out to us at šŸ”9953056974šŸ”
Ā 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
Ā 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
Ā 
Hį»ŒC Tį»T TIįŗ¾NG ANH 11 THEO CHĘÆĘ NG TRƌNH GLOBAL SUCCESS ĐƁP ƁN CHI TIįŗ¾T - Cįŗ¢ NĂ...
Hį»ŒC Tį»T TIįŗ¾NG ANH 11 THEO CHĘÆĘ NG TRƌNH GLOBAL SUCCESS ĐƁP ƁN CHI TIįŗ¾T - Cįŗ¢ NĂ...Hį»ŒC Tį»T TIįŗ¾NG ANH 11 THEO CHĘÆĘ NG TRƌNH GLOBAL SUCCESS ĐƁP ƁN CHI TIįŗ¾T - Cįŗ¢ NĂ...
Hį»ŒC Tį»T TIįŗ¾NG ANH 11 THEO CHĘÆĘ NG TRƌNH GLOBAL SUCCESS ĐƁP ƁN CHI TIįŗ¾T - Cįŗ¢ NĂ...
Ā 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
Ā 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
Ā 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
Ā 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Ā 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
Ā 
Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"
Ā 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
Ā 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
Ā 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
Ā 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
Ā 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
Ā 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
Ā 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Ā 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
Ā 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
Ā 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
Ā 

Managing console i/o operation,working with files

  • 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.