Javatpoint Logo
Javatpoint Logo

Tellg() Function in C++

The tellg() function is defined in the isstream class, which is used with input streams. The tellg() function returns the current "get" position of the pointer in the stream. It has no parameters and outputs a value of the integer data type member type pos_type, which represents the position of the get stream pointer at the moment.

Syntax:-

Returns:

If the request is successful, the get pointer's current location; if it is unsuccessful, pos_type(-1).

Let's take some examples to understand how tellg() function works in C++.

Example:1

Output:

After reading the word "JavaTpoint" tellg() returns -1

Example:2

Output:

After reading the word "welcome," tellg() returns 8.

Example:3

Explanation:

The program should read the "JTP.txt" file and report its contents to the console assuming that it is present in the same directory as the program and contains valid data.

You can compile and run the program on your own system to test it. Make sure the "JTP.txt" file is there and contains the appropriate information. The software should then show that information on the console.

Properties:-

Neither the file size nor the offset from the beginning in bytes is reported by the tellg() function. It only reports a token value that can be used in the future to seek to the same location.


Next TopicCoroutines in C++





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA