Random access file I/O functions in C++: seekg() and seekp()

seekg() and seekp() functions are used for random access or non linear sequence access of a file in C++.

Syntax of seekg() function:

istream &seekg(offset_type offset, seekdir origin);

Syntax of seekp() function:

ostream &seekp(offset_type offset, seekdir origin);

where, offset_type is integer type which can contain the largest value of offset. seekdir is an enumeration which is used to show the process on how to do seek. Both are defined by ios.

Leave a Reply