Namespaces
Variants
Views
Actions

std::basic_ostream::tellp

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

pos_type tellp();

Returns the output position indicator of the current associated streambuf object.

First, constructs a sentry object which checks the stream for errors and flushes the tie()'d output streams (since C++11). Afterwards, if fail()==true, returns pos_type(-1). Otherwise, returns rdbuf()->pubseekoff(0, std::ios_base::cur, std::ios_base::out).

Contents

Parameters

(none)

Return value

current output position indicator on success, pos_type(-1) if a failure occurs.

Example

#include <iostream>
#include <sstream>
int main()
{
    std::ostringstream s;
    std::cout << s.tellp() << '\n';
    s << 'h';
    std::cout << s.tellp() << '\n';
    s << "ello, world ";
    std::cout << s.tellp() << '\n';
    s << 3.14 << '\n';
    std::cout << s.tellp() << '\n' << s.str();
}

Output:

0
1
13
18
hello, world 3.14

See also

Template:cpp/io/basic ostream/dcl list seekpTemplate:cpp/io/basic istream/dcl list tellgTemplate:cpp/io/basic istream/dcl list seekg