std::getline() and istream::gcount()

I just stumbled across the following:

1
2
3
4
std::ifstream file;
file.open("filename");
std::getline(file, str);
std::cout << "Size of last get op: " << file.gcount() << std::endl;


This invariably gives '0' whether the read line was empty or not which might be understood considering std::getline() is NOT a member of the istream-class. However the doc for istream::gcount() states
[...] Returns the number of characters extracted by the last unformatted input operation performed on the object. [...]

Whereas the std::getline() doc states:
istream& getline ( istream& is, string& str, char delim );
[...]
Parameters:
is istream object on which the extraction operation is performed.[...]

Putting these two together I thought gcount() should also work for the global function std::getline().

* Is this standard behavior or just a quirk of my compiler?
* If it is standard, please help me to recognize this as consistent behavior.
* And lastly, if this is standard, please explicitly state in the docs of
std::getline() and istream::gcount() that they won't work together

Cheers,
J
This lists the operations gcount() works with: http://www.cplusplus.com/reference/iostream/istream/gcount/

I suppose you could always get the same information from std::getline() by checking the length of the string that was read?
Topic archived. No new replies allowed.