Namespaces
Variants
Views
Actions

std::basic_istream::tellg

From cppreference.com
< cpp‎ | io‎ | basic istream
Revision as of 21:07, 2 November 2012 by P12bot (Talk | contribs)

pos_type tellg();

Returns input position indicator of the current associated streambuf object.

Behaves as UnformattedInputFunction. 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).

Contents

Parameters

(none)

Return value

current position of the get pointer on success, pos_type(-1) on failure

Example

#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

Template:cpp/io/basic istream/dcl list seekgTemplate:cpp/io/basic ostream/dcl list tellpTemplate:cpp/io/basic ostream/dcl list seekp