File Operations (Cont)
File Operations (Cont)
(cont.)
Contents
FilePointers
Function for manipulation of file pointer
read() and write() function
How to delete record from a file
2
File Pointers
1. Each file have two associated pointers known as
the file pointers.
2. One of them is called the input pointer (or get pointer) and the
other is called the output pointer (or put pointer).
3. The input pointer is used for reading the contents of a given file
location
This statement moves the file pointer to the byte number 10.
The bytes in the a file are numbered beginning from zero. Therefore, the pointer
will be pointing to the 11th byte in the file.
On execution of these statement, The pointer is moved to the end of the file “hello”
and the value of p Will represent number of bytes in the file.
‘Seek’ functions
seekg() and seekp() can also be used with two arguments as follows:
Seekg(offset,refposition); , seekp(offset,refposition)
Offset represents the number of bytes the file pointer is to be moved from the
location specified by the parameter ref position.
Reference position takes one of the following three constants defined in the ios class
These function take two arguments. The first is the address of the
variable V , and the second is the length of that variable in bytes .
The address of variable must be cast to type char * (i.e pointer to
character type) .