std::basic_istream<CharT,Traits>::gcount
From cppreference.com
 
 
 < cpp | io | basic istream 
 
 
 C++ 
 Feature test macros (C++20)
 Concepts library (C++20)
 Metaprogramming library (C++11)
 Ranges library (C++20)
 Filesystem library (C++17)
 Concurrency support library (C++11)
 Execution control library (C++26)
Input/output library 
 
 
 
 
 
 
 
 
 
 
 
 
 Print functions (C++23)
 Buffers
(C++23)
(C++98/26*)
(C++20)
 Streams
 Abstractions
 File I/O
 String I/O
 Array I/O
(C++23)
(C++23)
(C++23)
(C++98/26*)
(C++98/26*)
(C++98/26*)
 Synchronized Output
(C++20)
 Types
 Error category interface
(C++11)
(C++11)
std::basic_istream 
 
 
 
 Global objects
 Member functions
(C++11)
 Formatted input
 Unformatted input
basic_istream::gcount
 Positioning
 Miscellaneous
(C++11)
 Member classes
 Non-member functions
std::streamsize gcount() const;
 
 
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.
The following member functions of basic_istream change the value of subsequent gcount() calls:
The following functions set gcount() to zero:
[edit] Parameters
(none)
[edit] 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.
[edit] 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
[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior | 
|---|---|---|---|
| LWG 3464 | C++98 | the return value was unspecified when the result overflows | returns the maximum value |