std::basic_ostream<CharT,Traits>::tellp

From cppreference.com
< cpp‎ | io‎ | basic ostream
 
 
Input/output library
I/O manipulators
C-style I/O
Buffers
(deprecated in C++98)
Streams
Abstractions
File I/O
String I/O
Array I/O
(deprecated in C++98)
(deprecated in C++98)
(deprecated in C++98)
Synchronized Output
Types
Error category interface
(C++11)
 
 
pos_type tellp();

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

Behaves as UnformattedOutputFunction (except without actually performing output). After constructing and checking the sentry object,

(since C++11)

If fail()==true, returns pos_type(-1). Otherwise, returns rdbuf()->pubseekoff(0, std::ios_base::cur, std::ios_base::out).

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

sets the output position indicator
(public member function)
returns the input position indicator
(public member function of std::basic_istream<CharT,Traits>)
sets the input position indicator
(public member function of std::basic_istream<CharT,Traits>)