std::basic_istream<CharT,Traits>::tellg
From cppreference.com
pos_type tellg(); |
||
Returns input position indicator of the current associated streambuf
object.
Behaves as Template:concept, except that gcount() is not affected.
After constructing and checking the sentry object, if fail() == true, returns pos_type(-1). Otherwise, returns rdbuf()->pubseekoff(0, std::ios_base::cur, std::ios_base::in).
The function returns correct value even if failbit is set.
Contents |
Parameters
(none)
Return value
The current position of the get pointer on success, pos_type(-1) on failure
Exceptions
If an internal operation throws an exception, it is caught and badbit is set. If exceptions() is set for badbit
, the exception is rethrown.
Example
Run this code
#include <iostream> #include <string> #include <sstream> int main() { std::string str = "Hello, world"; std::istringstream in(str); std::string word; in >> word; std::cout << "After reading the word \"" << word << "\" tellg() returns " << in.tellg() << '\n'; }
Output:
After reading the word "Hello," tellg() returns 6
See also
sets the input position indicator (public member function) | |
returns the output position indicator (public member function of std::basic_ostream<CharT,Traits> )
| |
sets the output position indicator (public member function of std::basic_ostream<CharT,Traits> )
|