File Pointer | File Handling In C++ | C++ Tutorials

14 May 20120 comments

Whenever you want to perform I/O operation with a file, there are two pointers associated with it. They are known as get pointer and put pointer. These pointers simply refer to the current position within the file from where reading or writing performed. The get pointer specify the location in the file from where the next input operation will occur. On the other hand, put pointer specify the location in the file from where the next output operation will occur. Each input/output operation sequentially advance the appropriate pointer automatically.

On opening a file, the appropriate file pointer is set to a suitable position within the file depending on the opening mode.

Read-only Mode: When a file is opened in read - only mode, the get pointer is automatically set to point to the beginning of the file so that file can be read from the start.

Write only Mode:  When a file is opened in write only mode, the existing contents of file are erased and the put pointer is set to point at the beginning of the file so that data can be written from the start.

Append Mode: When a file is opened in append mode, the put pointer is set to point at the end of the file so that data can be written at the end of the file.In case, the file does not exist, a new file is created and put pointer is set to point to the beginning of the file.

Tags : C++ Tutorials, File handling Tutorials in C++, File handling In C++, File pointers in file handling
Share this article :

Post a Comment

 
Copyright © 2011. All Compiler - All Rights Reserved