A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/basic_istream::gcount below:

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 safetyStrong guarantee: if an exception is thrown, there are no changes in the stream.

See also
basic_istream::get
Get characters (public member function)
basic_istream::getline
Get line (public member function)
basic_istream::ignore
Extract and discard characters (public member function)
basic_istream::read
Read block of data (public member function)
basic_istream::readsome
Read data available in buffer (public member function)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4