I was just wondering why the member functions tellg()
defined in basic_istream<>
class and tellp()
defined in basic_ostream<>
class have different names. Is that because basic_fstream<>
is derived from basic_istream<>
and basic_ostream<>
?
tellg() get the position of the get pointer and tellp() gets the position of the put pointer, one of them is the place where you read and the second- where you write in the file. So the two functions do different things and return different values.
tellp() gives the position of the put pointer. tellg() gives the position of the get pointer.
tellg() function in C++ with example 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.
In C++ file handling, the tellp() function is used with output streams, and returns the current put position of the pointer in the stream. It returns an integer data type, representing the current position of the stream pointer. tellp() method takes no parameter.
tellg()
get the position of the get
pointer and tellp()
gets the position of the put
pointer, one of them is the place where you read and the second- where you write in the file. So the two functions do different things and return different values. Why would you think they should have the same name?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With