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.
Returns: The current position of the get pointer on success, pos_type(-1) on failure.
After reading the word "geeksforgeeks" tellg() returns -1
Example 2 :
After reading the word "Hello," tellg() returns 6
tellg() does not report the size of the file, nor the offset from the beginning in bytes. It reports a token value which can later be used to seek to the same place, and nothing more. (It’s not even guaranteed that you can convert the type to an integral type)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Read a record from a File in C++ using seekg() and tellg()
- Command line arguments example in C
- Difference between Public and Private in C++ with Example
- Life cycle of Objects in C++ with Example
- %n in scanf() in C with Example
- How to call some function before main() function in C++?
- Difference between user defined function and library function in C/C++
- deque assign() function in C++ STL
- gmtime() Function in C/C++
- How to return multiple values from a function in C or C++?
- nearbyint() function in C++
- sqrt() function for complex number in C++
- imag() function in C++
- real() function in C++
- abs() function for complex number in c++
- sin() function for complex number in C++ with Examples
- cosh() function for complex number in C++
- polar() function for complex number in C++
- C++ Program to swap two members using Friend Function
- max() function for valarray in C++