std::basic_...f::showmanyc(3)

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

✨ std::basic_filebuf::showmanyc ✨

okay so bestie, welcome to the manual page for std::basic_filebuf::showmanyc β€” that's the whole NAME situation, both halves, we're not skipping a single crumb πŸ’…

This one's living in the C++ Standard Library and it's lowkey one of those little hidden gems you only meet when you go digging. Let's get into it πŸŽ€


🌸 Synopsis

protected:
virtual std::streamsize showmanyc()

So it's a protected virtual member function, and β€” if it's actually implemented β€” it hands you back the number of characters left to read from the file. that's the whole vibe. πŸ¦‹


πŸ’– Parameters

none. zero. nada. she takes no arguments, she needs no arguments, she's confident like that πŸ™ˆ


⭐ Return value

She gives you the number of characters available for reading from the file β€” or -1 if the end of file was reached. that's it, that's the whole dealio. -1 means EOF, don't @ me 😭


🧚 Notes

okay this part is important so listen up:

  • This function is optional. If it's not implemented, it returns 0 β€” and the reason is that the base class version std::basic_streambuf::showmanyc gets called instead. inherited behaviour, classic πŸ’€
  • Whether it's implemented or not, this function is normally called by std::basic_streambuf::in_avail if the get area is empty. so like, she's the backup dancer who gets called on stage when the main area's empty, yk? πŸ‘‘
  • And the naming lore 🫢 β€” the name stands for "stream: how many characters?", which means you pronounce it "S how many C", not "show many C". this is the detail that separates the girlies who read the docs from the ones who don't. iykyk πŸ”₯
fr fr say it out loud: "S how many C". it's giving acronym, not it's giving verb. periodt.

🌈 Example

here's an implementation test to see if showmanyc() is implemented for filebuf β€” cute little trick with using to expose the protected member:

// Run this code

#include <fstream>
#include <iostream>

struct mybuf : std::filebuf
{
     using std::filebuf::showmanyc;
};

int main()
{
    mybuf fin;
    fin.open("main.cpp", std::ios_base::in);
    std::cout << "showmanyc() returns " << fin.showmanyc() << '\n';
}

Possible output:

showmanyc() returns 267

(267 is not a magic number bestie, it's just however many characters were in main.cpp at the time, don't come for me 😭)


πŸ‘‘ See also

  • in_avail β€” obtains the number of characters immediately available in the get area (public member function of std::basic_streambuf<CharT,Traits>)
  • readsome β€” extracts already available blocks of characters (public member function of std::basic_istream<CharT,Traits>)

πŸ“ quick vibe check: this page is protected: + virtual, optional, returns 0 when unimplemented, -1 at EOF, and is pronounced "S how many C". that's the tea. slay. ✨

and that's the page!! source is http://cppreference.com, dated 2024.06.10, and it's the man page for std::basic_...f::showmanyc(3) β€” the C++ Standard Library girlies stay winning πŸ’œπŸ«ΆπŸŽ€

πŸ“¦ where this page comes from