Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Upcoming SlideShare
file handling c++
Next
Download to read offline and view in fullscreen.

4

Share

Download to read offline

File Pointers

Download to read offline

Related Books

Free with a 30 day trial from Scribd

See all

File Pointers

  1. 1. FILE HANDLING IN C++
  2. 2. STREAMS <ul><li>A Stream is a general name given to flow of data. </li></ul><ul><li>Different streams are used to represent different kinds of data flow. </li></ul><ul><li>Each stream is associated with a particular class, which contains member functions and definitions for dealing with that particular kind of data flow. </li></ul>
  3. 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. 4. DIFFERENT FILE OPERATIONS <ul><li>OPENING A FILE </li></ul><ul><li>CLOSING A FILE </li></ul><ul><li>READING FROM A FILE </li></ul><ul><li>WRITING ON A FILE </li></ul><ul><li>CHECKING FOR END OF FILE </li></ul>
  5. 5. File Mode Parameters <ul><li>PARAMETER MEANING </li></ul><ul><li>Ios::app Append to end-of file </li></ul><ul><li>Ios::ate goto end of file on opening </li></ul><ul><li>Ios::binary binary file </li></ul><ul><li>Ios::in </li></ul><ul><li>Ios::nocreate open fails if file doesn’t exist </li></ul><ul><li>Ios::noreplace open fails if file already exists </li></ul><ul><li>Ios::out </li></ul><ul><li>Ios::trunc Deletes contents if it exists </li></ul>
  6. 6. FILE POINTERS
  7. 7. FILE POINTERS <ul><li>Each file object has two integer values associated with it : </li></ul><ul><ul><li>get pointer </li></ul></ul><ul><ul><li>put pointer </li></ul></ul><ul><li>These values specify the byte number in the file where reading or writing will take place. </li></ul>
  8. 8. File pointers….. <ul><li>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) </li></ul><ul><li>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. </li></ul>
  9. 9. Functions associated with file pointers : <ul><li>The seekg() and tellg() functions allow you to set and examine the get pointer. </li></ul><ul><li>The seekp() and tellp() functions allow you to set and examine the put pointer. </li></ul>
  10. 10. seekg() function : <ul><li>With one argument : </li></ul><ul><li>seekg(k) where k is absolute position from the beginning. The start of the file is byte 0 </li></ul>Begin File End k bytes ^ File pointer The seekg() function with one argument
  11. 11. seekg() function : <ul><li>With two arguments : </li></ul><ul><ul><li>the first argument represents an offset from a particular location in the file. </li></ul></ul><ul><ul><li>the second specifies the location from which the offset is measured. </li></ul></ul>Begin End ^ Offset from Begin The seekg() function with two argument
  12. 12. seekg() function : <ul><li>With two arguments : </li></ul>Begin End ^ Offset from Begin The seekg() function with two argument ^ ^ Offset from end Offset from current position
  • ShefaIdrees

    Jul. 18, 2017
  • madhurkant

    Dec. 19, 2016
  • gigigeorge351

    Jun. 25, 2014
  • muhammadyousafch

    Dec. 5, 2013

Views

Total views

15,244

On Slideshare

0

From embeds

0

Number of embeds

37

Actions

Downloads

547

Shares

0

Comments

0

Likes

4

×