Posted By:
4 Jul, 2013 1:34 pm PDT

File Pointers in C++

What are file pointers? For what purpose they are used?
Attachment:None


Each file object has two integer values associated with it. They are:

  1. get pointer
  2. put pointer

The get pointer specifies a location from which the current reading operation is initiated. The put pointer specifies a location from which the current writing operation is initiated.

 

We can use these pointers to move through the files while reading or writing.

Following are the functions for manipulation of file pointers:

  1. seekg() moves get pointer to specified location
  2. seekp() moves put pointer to specified location
  3. tellg() gives the current position of the get pointer
  4. tellp() gives the current position of the put pointer

 

The first prototype for seekg() and seekp() are:

seekg (position);

seekp (position);

 

The second prototype for seekg() and seekp() are:

seekg ( position, direction);

seekp (position, direction);

 

The direction can be of three formats: ios::beg, ios::cur, ios::end

Was it useful?  




Please login to reply to this problem.