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()
- Function Interposition in C with an example of user defined malloc()
- wcstok() function in C++ with example
- wcsstr() function in C++ with example
- wcsncpy() function in C++ with example
- Buffer Overflow Attack with Example
- fseek() in C/C++ with example
- Writing first C++ program : Hello World example
- std::search_n with example in C++
- tellp() in file handling with c++ with example
- Command line arguments example in C
- vector::crend() & vector::crbegin() with example
- asin() and atan() functions in C/C++ with Example
- forward_list::cend() in C++ STL with Example
- Difference between Public and Private in C++ with Example
- Difference between Private and Protected in C++ with Example
- std::is_destructible in C++ with Example
- std::is_nothrow_move_constructible in C++ with Example
- std::is_trivially_default_constructible in C++ with Example
- std::numeric_limits<T>::denorm_min() in C++ with Example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.