Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

iostream

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?

like image 571
Andrew Tomazos Avatar asked Dec 04 '18 08:12

Andrew Tomazos


People also ask

What is Tellg?

The tellg() function is used with input streams, and returns the current “get” position of the pointer in the stream. It has no parameters and returns a value of the member type pos_type, which is an integer data type representing the current position of the get stream pointer.

What is the Tellg () and Tellp ()?

tellp() gives the position of the put pointer. tellg() gives the position of the get pointer.

What is the difference between seekg and Seekp?

seekg() and seekp() both are functions of File Handling in C++ and they are very important and useful feature of File Handling in C++. In File Handling of C++, we have two pointers one is get pointer and second is put pointer.

What is the use of seekg in C++?

seekg() is a function in the iostream library that allows us to seek an arbitrary position in a file. It is mainly used to set the position of the next character to be extracted from the input stream from a given file in C++ file handling.


1 Answers

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.

like image 98
Stephan Lechner Avatar answered Oct 02 '22 05:10

Stephan Lechner