File Handling by Ankur Sir Test Ppt

Download as
 PPT
Presentation Description 

No description available

By:
 (1 month(s) ago)  
too good benefecial 4 me .allow 2 download it

By:
 (1 month(s) ago)  
download this presentation

By:
 (2 month(s) ago)  
give me your email id and tell for what purpose you want this file .? email me a t study0070@hotmail.com
 (1 month(s) ago)
kavita_surjeet@rediffmail.com

By:
 (2 month(s) ago)  
Sir,please allow me to dow nload. Thanks
 (2 month(s) ago)
may i know for what purpsoe u want b true.?

By:
 (2 month(s) ago)  
i like ur prsentation can u send it to me.
 (2 month(s) ago)
give me your email id and tell for what purpose you want this file .? email me a t study0070@hotmail.com

Previous 1 2
Views: 1046
Like it  ( Likes) Dislike it  ( Dislikes)
Added: September 29, 2008 This Presentation is Public 
Presentation Category : Education All Rights Reserved
Tags Add Tags
Presentation Statistics
Views on authorSTREAM: 1008 | Views from Embeds: 38
Others - 38 views
Presentation Transcript

FILE HANDLING IN C++ :FILE HANDLING IN C++


C++ STREAMS :C++ STREAMS A Stream is a general name given to flow of data. Different streams are used to represent different kinds of data flow. Each stream is associated with a particular class, which contains member functions and definitions for dealing with that particular kind of data flow.


Flow of Data…. :Flow of Data…. PROGRAM DEVICES OR FILES Input Stream >> Output Stream << Data Data istream class ostream class (Insertion operator) (Extraction operator)


The following classes in C++ have access to file input and output functions: :The following classes in C++ have access to file input and output functions: ifstream ofstream fstream


The Stream Class Hierarchy :The Stream Class Hierarchy ios istream get() getline() read() >> ostream put() write() << fstreambase iostream Ifstream Open() Tellg() Seekg() Ofstream Open() Tellp() Seekp() fstream NOTE : UPWARD ARROWS INDICATE THE BASE CLASS


DIFFERENT FILE OPERATIONS :DIFFERENT FILE OPERATIONS OPENING A FILE CLOSING A FILE READING FROM A FILE WRITING ON A FILE CHECKING FOR END OF FILE


Slide 7:A binary file stores data to disk in the same form in which it is represented in main memory. If you ever try to edit a binary file containing numbers you will see that the numbers appear as nonsense characters. Not having to translate numbers into a readable form makes binary files somewhat more efficient. Binary files also do not normally use anything to separate the data into lines. Such a file is just a stream of data with nothing in particular to separate components.


Slide 8:When using a binary file we write whole record data to the file at once. When using a text file, we write out separately each of the pieces of data about a given record. The text file will be readable by an editor, but the numbers in the binary file will not be readable in this way. The programs to create the data files will differ in how they open the file and in how they write to the file.


Slide 9:For the binary file we will use write to write to the file, whereas for the text file we will use the usual output operator(>)


EXAMPLES :EXAMPLES Creation of a text file


:Sequential access. With this type of file access one must read the data in order, much like with a tape, whether the data is really stored on tape or not. Random access (or direct access). This type of file access lets you jump to any location in the file, then to any other, etc., all in a reasonable amount of time. ::Sequential access. With this type of file access one must read the data in order, much like with a tape, whether the data is really stored on tape or not. Random access (or direct access). This type of file access lets you jump to any location in the file, then to any other, etc., all in a reasonable amount of time. Types of File Access


seekg() function : :seekg() function : With one argument : seekg(k) where k is absolute position from the beginning. The start of the file is byte 0 Begin File End k bytes ^ File pointer The seekg() function with one argument


Slide 13:seekg() function : With two arguments : the first argument represents an offset from a particular location in the file. the second specifies the location from which the offset is measured. Begin End ^ Offset from Begin The seekg() function with two argument


Slide 14:seekg() function : With two arguments : Begin End ^ Offset from Begin The seekg() function with two argument ^ ^ Offset from end Offset from current position