What does the g stand for in gcount, tellg and seekg?

C++Iostream

C++ Problem Overview


What does the g stand for in std::iostream's gcount, tellg and seekg members? And the p in pcount, tellp and seekp?

Why aren't they called just count, tell and seek?

C++ Solutions


Solution 1 - C++

In streams supporting both read and write, you actually have two positions, one for read (i.e. "get" denoted by "g") and one for write (i.e. "put" denoted by a "p").

And that's why you have a seekp (inherited from basic_ostream), and a seekg (inherited from basic_istream).

Side note: The language C has - in contrast to C++ - only one such function fseek for both pointers; There it is necessary to re-position the pointer when switching from read to write and vice versa (cf., for example, this answer). To avoid this, C++ offers separate functions for read and write, respectively.

Solution 2 - C++

C++ offers two pointers while navigating the file: the get pointer and the put pointer. The first one is used for read operations, the second one for write operations.

> - seekg() is used to move the get pointer to a desired location with respect to a reference point. > > - tellg() is used to know where the get pointer is in a file. > > - seekp() is used to move the put pointer to a desired location with respect to a reference point. > > - tellp() is used to know where the put pointer is in a file.

Main source: Quora, answer by Gunjan B. Yadav on Dec 1, 2017.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAndrew TomazosView Question on Stackoverflow
Solution 1 - C++Stephan LechnerView Answer on Stackoverflow
Solution 2 - C++Tu.Ma.View Answer on Stackoverflow