C++ basic_ios Library - gcount


Advertisements

Description

It is used to get character count.

Declaration

Following is the declaration for std::basic_istream::gcount.

streamsize gcount() const;

Parameters

none

Return Value

Returns the number of characters extracted by the last unformatted input operation performed on the object.

Exceptions

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

Data races

Accesses the stream object.

Example

In below example for std::basic_istream::gcount.

#include <iostream>     

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;
}

Let us compile and run the above program, this will produce the following result −

Please, enter a word: simplify
9 characteres read: simplify
istream.htm
Advertisements