AlgoMaster Logo

File Positioning

Last Updated: June 6, 2026

Low Priority
36 min read

A file stream isn't always read or written from start to finish. Sometimes the code needs to skip a 16-byte header, jump back to a specific record, measure the file's size, or update one field inside an existing record without rewriting the whole file. C++ exposes these patterns through four member functions on file streams: tellg, tellp, seekg, and seekp. They report and change the current position of the file pointer, the abstract cursor that says where the next read or write will happen. This lesson covers what the file pointer is, how the four functions are used, the three seek directions (beg, cur, end), the patterns this enables (skipping headers, file-size measurement, in-place updates), and the subtle differences between text and binary mode.

Premium Content

Subscribe to unlock full access to this content and more premium articles.