std::basic_ostream::tellp(3)
π std::basic_ostream::tellp β C++ Standard Library, but make it make sense
okay so bestie, welcome to std::basic_ostream::tellp(3) from the C++ Standard Library β yes that's the whole manual name, we're being official today π. This one's a little function with big main character energy: it tells you where you are in your output stream. That's it. That's the vibe. Let's get into it β¨
π NAME
std::basic_ostream::tellp β literally std::basic_ostream::tellp, no notes, the name ate π
πΈ Synopsis
pos_type tellp();
So what does it actually do? It returns the output position indicator of the current associated streambuf object. Think of it as the little cursor bookmark of your output stream β where's the next character gonna land? This function knows π₯
It behaves as an UnformattedOutputFunction (except without actually performing output) β and heads up, that "(since C++11)" applies to that no-actual-output part. After constructing and checking the sentry object:
- If
fail()==true, it returnspos_type(-1). - Otherwise, it returns
rdbuf()->pubseekoff(0, std::ios_base::cur, std::ios_base::out).
Yes the whole call is that long, no we're not abbreviating it, character for character bestie π«Ά
π Parameters
- (none) β she takes nothing, she gives everything. Periodt.
π Return value
- current output position indicator on success β
pos_type(-1)if a failure occurs π
That's the whole deal. Success = a real position, failure = that sad little -1.
π¦ Example
the original page has one of those // Run this code buttons, and here's the code it runs:
#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
and honestly? watching the position tick up 0 β 1 β 13 β 18 while the string quietly builds itself into hello, world 3.14 is lowkey iconic π
π See also
seekpβ sets the output position indicator (public member function)tellgβ returns the input position indicator (public member function ofstd::basic_istream<CharT,Traits>)seekgβ sets the input position indicator (public member function ofstd::basic_istream<CharT,Traits>)
like tellp's whole friend group fr fr π
aaaand that's the page! source is http://cppreference.com, version 2024.06.10, and this gorgeous little entry is std::basic_ostream::tellp(3) β go check your stream position bestie, ily, bye π
β¨π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms