std::ostrstream::pcount(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

✨ NAME ✨

Okay bestie, welcome to the std::ostrstream::pcount(3) page from the C++ Standard Libary manual 🫢. The name is literally std::ostrstream::pcount β€” std::ostrstream::pcount (yes, it said it twice, and honestly? iconic πŸ’…).


🧚 Synopsis 🧚

Here's the signature, no cap:

int pcount() const;  (deprecated in C++98)
                     (removed in C++26)
⚠️ Important vibe check: this is deprecated in C++98 and removed in C++26. So like... it's giving legacy era, bestie πŸ’€.

So what does it actually do? It returns the number of characters that were output in the put area of the associated std::strstreambuf 🌸. Effectively calls rdbuf()->pcount().


πŸ™ˆ Parameters πŸ™ˆ

None. Literally none. Zero. Nada. No arguments to pass, bestie 🫢.


πŸ’– Return value πŸ’–

The number of characters in the put area, or zero if nothing was output. That's it. That's the whole return-value moment ✨.


🌈 Example 🌈

// Run this code β€” like, go off πŸ‘‡

#include <iostream>
#include <strstream>

int main()
{
    std::ostrstream dyn; // dynamically-allocated output buffer
    dyn << "Test: " << 1.23 << std::ends;
    std::cout << "The size of the output is " << dyn.pcount()
              << " and it holds \"" << dyn.str() << "\"\n";
    dyn.freeze(false);

    char buf[10];
    std::ostrstream user(buf, 10); // user-provided output buffer
    user << 1.23; // note: no std::ends
    std::cout.write(buf, user.pcount());
    std::cout << '\n';
}

πŸ–₯️ Output πŸ–₯️

The size of the output is 11 and it holds "Test: 1.23"
1.23

πŸ‘€ See also πŸ‘€

  • pcount β€” returns the next pointer minus the beginning pointer in the output sequence: pcount is the number of characters written (public member function of std::strstreambuf). πŸ‘‘

And that's the page, bestie πŸ’œ. Source/version: http://cppreference.com, dated 2024.06.10 β€” cute little footer folded into this sign-off instead of copied as a line πŸŽ€. Bye! πŸ¦‹

πŸ“¦ where this page comes from