std::basic_istream::gcount(3)

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

πŸ’… std::basic_istream::gcount(3) β€” C++ Standard Library πŸ’…

okay bestie, this one's from the C++ Standard Library manual, and it's giving β€œhow many characters did we just slurp?” energy. No cap.

✨ NAME ✨

std::basic_istream::gcount - std::basic_istream::gcount

(Yes, the name is literally the same on both sides β€” iconic minimalism, periodt.)

πŸ¦‹ Synopsis πŸ¦‹

std::streamsize gcount() const;

It returns the number of characters extracted by the last unformatted input operation, or the maximum representable value of std::streamsize if the number is not representable. Lowkey vital.

The following member functions of basic_istream change the value of subsequent gcount() calls:

  • move constructor
  • swap()
  • get()
  • getline()
  • ignore()
  • read()
  • readsome()
  • operator>>(basic_streambuf*)

The following functions set gcount() to zero:

  • constructor
  • putback()
  • unget()
  • peek()

πŸŽ€ Parameters πŸŽ€

(none)

Yep, no parameters. She takes nothing. Main character energy.

πŸ’– Return value πŸ’–

The number of characters extracted by the last unformatted input operation, or the maximum representable value of std::streamsize if the number is not representable.

🌈 Example 🌈

// Run this code

#include <iostream>
#include <sstream>

int main()
{
    char x[20];
    std::istringstream stream("Hello World");

    stream.read(x, sizeof x);
    std::cout << "Characters extracted: " << stream.gcount();
}

⭐ Output ⭐

Characters extracted: 11

🧚 Defect reports 🧚

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

  • LWG 3464, applied to C++98 β€” behavior as published: β€œthe return value was unspecified when the result overflows”; correct behavior: β€œreturns the maximum value”.

okay byeee, bestie 🫢 β€” source: http://cppreference.com, version/date: 2024.06.10 πŸ’–

πŸ“¦ where this page comes from