std::basic_istream::gcount(3)
π 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
- 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