问题
I'm finding that gcount on an ifstream object after a call to
getline(istream &, string &)
returns 0.
Is this supposed to be the case?
回答1:
Yes, gcount()
is supposed to return the number of characters extracted by the last unformatted input operation performed on the object.
getline()
is listed in the functions supposed to updated gcount()
, but it is the member getline() of a stream and not the string getline().
In case of doubt, this link tells it black on white: Behaves as UnformattedInputFunction, except that input.gcount() is not affected.
来源:https://stackoverflow.com/questions/28600797/ifstream-gcount-returns-0-on-getline-string-overload