SlideShare ist ein Scribd-Unternehmen logo
1 von 17
M.SUJITHA,
M.SC Student,
N.S College, Theni.
C++ STREAM CLASSES
 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();
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
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);
 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;
 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.
 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”);
This condition is necessary for preventing
and read data from the file.
MORE ABOUT OPEN( ): FILE MODES
The function open( ) is used to open a new
and an existing file.
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!!!

Weitere ähnliche Inhalte

Was ist angesagt?

intro unix/linux 04
intro unix/linux 04intro unix/linux 04
intro unix/linux 04duquoi
 
Trace File Database admanistartion and manegment
Trace File Database admanistartion and manegmentTrace File Database admanistartion and manegment
Trace File Database admanistartion and manegmentKainat Ilyas
 
intro unix/linux 02
intro unix/linux 02intro unix/linux 02
intro unix/linux 02duquoi
 
Directory Commands - R.D.Sivakumar
Directory Commands - R.D.SivakumarDirectory Commands - R.D.Sivakumar
Directory Commands - R.D.SivakumarSivakumar R D .
 
intro unix/linux 08
intro unix/linux 08intro unix/linux 08
intro unix/linux 08duquoi
 
How to process csv files
How to process csv filesHow to process csv files
How to process csv filesTukaram Bhagat
 
Free Space Management, Efficiency & Performance, Recovery and NFS
Free Space Management, Efficiency & Performance, Recovery and NFSFree Space Management, Efficiency & Performance, Recovery and NFS
Free Space Management, Efficiency & Performance, Recovery and NFSUnited International University
 
User and groups administrator
User  and  groups administratorUser  and  groups administrator
User and groups administratorAisha Talat
 
intro unix/linux 07
intro unix/linux 07intro unix/linux 07
intro unix/linux 07duquoi
 
Vb lecture notes
Vb lecture notesVb lecture notes
Vb lecture notesalldesign
 
Course 102: Lecture 28: Virtual FileSystems
Course 102: Lecture 28: Virtual FileSystems Course 102: Lecture 28: Virtual FileSystems
Course 102: Lecture 28: Virtual FileSystems Ahmed El-Arabawy
 
intro unix/linux 11
intro unix/linux 11intro unix/linux 11
intro unix/linux 11duquoi
 
help with Linux/Unix starting
help with Linux/Unix startinghelp with Linux/Unix starting
help with Linux/Unix startingdummy
 

Was ist angesagt? (20)

File handling
File handlingFile handling
File handling
 
intro unix/linux 04
intro unix/linux 04intro unix/linux 04
intro unix/linux 04
 
Trace File Database admanistartion and manegment
Trace File Database admanistartion and manegmentTrace File Database admanistartion and manegment
Trace File Database admanistartion and manegment
 
intro unix/linux 02
intro unix/linux 02intro unix/linux 02
intro unix/linux 02
 
Directory Commands - R.D.Sivakumar
Directory Commands - R.D.SivakumarDirectory Commands - R.D.Sivakumar
Directory Commands - R.D.Sivakumar
 
intro unix/linux 08
intro unix/linux 08intro unix/linux 08
intro unix/linux 08
 
How to process csv files
How to process csv filesHow to process csv files
How to process csv files
 
Free Space Management, Efficiency & Performance, Recovery and NFS
Free Space Management, Efficiency & Performance, Recovery and NFSFree Space Management, Efficiency & Performance, Recovery and NFS
Free Space Management, Efficiency & Performance, Recovery and NFS
 
Python - Lecture 11
Python - Lecture 11Python - Lecture 11
Python - Lecture 11
 
User and groups administrator
User  and  groups administratorUser  and  groups administrator
User and groups administrator
 
intro unix/linux 07
intro unix/linux 07intro unix/linux 07
intro unix/linux 07
 
MS-DOS
MS-DOSMS-DOS
MS-DOS
 
OSCh11
OSCh11OSCh11
OSCh11
 
File Systems
File SystemsFile Systems
File Systems
 
Vb lecture notes
Vb lecture notesVb lecture notes
Vb lecture notes
 
Course 102: Lecture 28: Virtual FileSystems
Course 102: Lecture 28: Virtual FileSystems Course 102: Lecture 28: Virtual FileSystems
Course 102: Lecture 28: Virtual FileSystems
 
intro unix/linux 11
intro unix/linux 11intro unix/linux 11
intro unix/linux 11
 
File allocation methods (1)
File allocation methods (1)File allocation methods (1)
File allocation methods (1)
 
Set path
Set pathSet path
Set path
 
help with Linux/Unix starting
help with Linux/Unix startinghelp with Linux/Unix starting
help with Linux/Unix starting
 

Ähnlich wie Managing console of I/o operations & working with files

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
 
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
 
File handling in_c
File handling in_cFile handling in_c
File handling in_csanya6900
 
File Handling In C++(OOPs))
File Handling In C++(OOPs))File Handling In C++(OOPs))
File Handling In C++(OOPs))Papu Kumar
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++Shyam Gupta
 
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.pptx
File handling.pptxFile handling.pptx
File handling.pptxVishuSaini22
 
Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008guestd9065
 
Working with the IFS on System i
Working with the IFS on System iWorking with the IFS on System i
Working with the IFS on System iChuck Walker
 
CSE3146-ADV JAVA M2.pdf
CSE3146-ADV JAVA M2.pdfCSE3146-ADV JAVA M2.pdf
CSE3146-ADV JAVA M2.pdfVithalReddy3
 
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
 
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
 

Ähnlich wie Managing console of I/o operations & working with files (20)

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
 
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
 
File handling in_c
File handling in_cFile handling in_c
File handling in_c
 
Filehandlinging cp2
Filehandlinging cp2Filehandlinging cp2
Filehandlinging cp2
 
File Handling In C++(OOPs))
File Handling In C++(OOPs))File Handling In C++(OOPs))
File Handling In C++(OOPs))
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes 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
 
File Handling In C++
File Handling In C++File Handling In C++
File Handling In C++
 
File handling.pptx
File handling.pptxFile handling.pptx
File handling.pptx
 
Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008
 
Working with the IFS on System i
Working with the IFS on System iWorking with the IFS on System i
Working with the IFS on System i
 
Project report
Project reportProject report
Project report
 
Java IO
Java IOJava IO
Java IO
 
File Handling in C++
File Handling in C++File Handling in C++
File Handling in C++
 
CSE3146-ADV JAVA M2.pdf
CSE3146-ADV JAVA M2.pdfCSE3146-ADV JAVA M2.pdf
CSE3146-ADV JAVA M2.pdf
 
File Handling
File HandlingFile Handling
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)
 
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
 

Mehr von lalithambiga kamaraj (20)

Firewall in Network Security
Firewall in Network SecurityFirewall in Network Security
Firewall in Network Security
 
Data Compression in Multimedia
Data Compression in MultimediaData Compression in Multimedia
Data Compression in Multimedia
 
Data CompressionMultimedia
Data CompressionMultimediaData CompressionMultimedia
Data CompressionMultimedia
 
Digital Audio in Multimedia
Digital Audio in MultimediaDigital Audio in Multimedia
Digital Audio in Multimedia
 
Network Security: Physical security
Network Security: Physical security Network Security: Physical security
Network Security: Physical security
 
Graphs in Data Structure
Graphs in Data StructureGraphs in Data Structure
Graphs in Data Structure
 
Package in Java
Package in JavaPackage in Java
Package in Java
 
Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in Java
 
Data structure
Data structureData structure
Data structure
 
Digital Image Processing
Digital Image ProcessingDigital Image Processing
Digital Image Processing
 
Digital Image Processing
Digital Image ProcessingDigital Image Processing
Digital Image Processing
 
Estimating Software Maintenance Costs
Estimating Software Maintenance CostsEstimating Software Maintenance Costs
Estimating Software Maintenance Costs
 
Datamining
DataminingDatamining
Datamining
 
Digital Components
Digital ComponentsDigital Components
Digital Components
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating system
 
Io management disk scheduling algorithm
Io management disk scheduling algorithmIo management disk scheduling algorithm
Io management disk scheduling algorithm
 
Recovery system
Recovery systemRecovery system
Recovery system
 
File management
File managementFile management
File management
 
Preprocessor
PreprocessorPreprocessor
Preprocessor
 
Inheritance
InheritanceInheritance
Inheritance
 

Kürzlich hochgeladen

Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...DhatriParmar
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationdeepaannamalai16
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxSayali Powar
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Developmentchesterberbo7
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfPrerana Jadhav
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research DiscourseAnita GoswamiGiri
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17Celine George
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxMichelleTuguinay1
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Association for Project Management
 
week 1 cookery 8 fourth - quarter .pptx
week 1 cookery 8  fourth  -  quarter .pptxweek 1 cookery 8  fourth  -  quarter .pptx
week 1 cookery 8 fourth - quarter .pptxJonalynLegaspi2
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 

Kürzlich hochgeladen (20)

Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
Mattingly "AI & Prompt Design: Large Language Models"
Mattingly "AI & Prompt Design: Large Language Models"Mattingly "AI & Prompt Design: Large Language Models"
Mattingly "AI & Prompt Design: Large Language Models"
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentation
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Development
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdf
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research Discourse
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
 
week 1 cookery 8 fourth - quarter .pptx
week 1 cookery 8  fourth  -  quarter .pptxweek 1 cookery 8  fourth  -  quarter .pptx
week 1 cookery 8 fourth - quarter .pptx
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 

Managing console of I/o operations & working with files

  • 3.  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.
  • 4.  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();
  • 5. 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;
  • 6. 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 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);
  • 7.  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;
  • 8.  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.
  • 9.  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.
  • 10.  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”);
  • 11. This condition is necessary for preventing and read data from the file. MORE ABOUT OPEN( ): FILE MODES The function open( ) is used to open a new and an existing file. stream-object. open(“file name”,mode);
  • 12. 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
  • 13. 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.
  • 14.  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
  • 15.  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.
  • 16.  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.