public member function
<istream> <iostream>

std::basic_istream::gcount

streamsize gcount() const;
Get character count
Returns the number of characters extracted by the last unformatted input operation performed on the object.

The unformatted input operations that modify the value returned by this function are: get, getline, ignore, peek, read, readsome, putback and unget.

Notice though, that peek, putback and unget do not actually extract any characters, and thus gcount will always return zero after calling any of them.

Parameters

none

Return Value

The number of characters extracted by the last unformatted input operation.
streamsize is a signed integral type.

Example

1
2
3
4
5
6
7
8
9
10
11
12
// cin.gcount example
#include <iostream>     // std::cin, std::cout

int main () {
  char str[20];

  std::cout << "Please, enter a word: ";
  std::cin.getline(str,20);
  std::cout << std::cin.gcount() << " characters read: " << str << '\n';

  return 0;
}


Possible output:
Please, enter a word: simplify
9 characteres read: simplify

Data races

Accesses the stream object.
Concurrent access to the same stream object may cause data races.

Exception safety

Strong guarantee: if an exception is thrown, there are no changes in the stream.

See also

<istream>