• Like
File Pointers
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Published

 

Published in Technology , Education
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
6,334
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
266
Comments
0
Likes
2

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. FILE HANDLING IN C++
  • 2. 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.
  • 3. 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
  • 4. DIFFERENT FILE OPERATIONS
    • OPENING A FILE
    • CLOSING A FILE
    • READING FROM A FILE
    • WRITING ON A FILE
    • CHECKING FOR END OF FILE
  • 5. File Mode Parameters
    • PARAMETER MEANING
    • Ios::app Append to end-of file
    • Ios::ate goto end of file on opening
    • Ios::binary binary file
    • Ios::in
    • Ios::nocreate open fails if file doesn’t exist
    • Ios::noreplace open fails if file already exists
    • Ios::out
    • Ios::trunc Deletes contents if it exists
  • 6. FILE POINTERS
  • 7. FILE POINTERS
    • Each file object has two integer values associated with it :
      • get pointer
      • put pointer
    • These values specify the byte number in the file where reading or writing will take place.
  • 8. File pointers…..
    • By default reading pointer is set at the beginning and writing pointer is set at the end (when you open file in ios::app mode)
    • There are times when you must take control of the file pointers yourself so that you can read from and write to an arbitrary location in the file.
  • 9. Functions associated with file pointers :
    • The seekg() and tellg() functions allow you to set and examine the get pointer.
    • The seekp() and tellp() functions allow you to set and examine the put pointer.
  • 10. 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
  • 11. 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
  • 12. seekg() function :
    • With two arguments :
    Begin End ^ Offset from Begin The seekg() function with two argument ^ ^ Offset from end Offset from current position