The various unformatted input functions on std::istream
(well, really, std::basic_istream
) like read()
, readsome()
, getline()
, and ignore()
all return a stream. When processing the results it is often important to know how many character were actually read. Relying on a null character in the string obviously doesn't work for binary files or ignore()
which doesn't even involve any string, i.e., something like strlen()
is entirely out of question.
How can the number of characters which were read by the last unformatted input operation using an std::istream
, or more generally, std::basic_istream
, be determined?
Use the gcount()
member function of the basic_istream
base class to retrieve the count of characters obtained by the last unformatted input operation.