Namespaces
Variants
Actions

Talk:cpp/io/basic istream/getline

From cppreference.com
< Talk:cpp‎ | io

Request for clarity on what is the char_type: It is not clear to me what type a char_type is. It makes me wonder if it will accept std::string*, for instance, as well as char*. I feel like what a char_type is needs to be better explained, or at least a link to an explanation should be added. This is one of the many cases where the cplusplus.com reference pages are far easier to read and understand, and where I would recommend someone read them instead of the cppreference.com pages: http://www.cplusplus.com/reference/istream/istream/getline/. ERCaGuy (Gabriel Staples) (talk) 19:36, 31 January 2022 (PST)

char_type is another member of the same class, it appears in the list of class members one page up, at cpp/io/basic_istream (and happens to be an alias to CharT, a type you, the programmer, either pick from the predefined options or configure up yourself through char_traits). You're correct that cppreference needs (auto-)linking of member types from where they are used in the argument lists of member functions - that affects many pages. As for cplusplus.com, the matching page there is http://www.cplusplus.com/reference/istream/basic_istream/getline/ --Cubbi (talk) 21:08, 31 January 2022 (PST)

it is never explained how the return type of getline (reference to the original stream object) can be used as a condition in a for/while loop. I believe there is a cast to bool defined for the stream which is "false" if the object is in a failed/end state. 128.250.26.7 05:15, 1 November 2013 (PDT)

it is explained in std::basic_ios::operator bool. Same applies to most stream input operations, getline isn't special. It could be helpful to mention that in comments to this page's example, true. (and now it is mentioned) --Cubbi (talk) 06:24, 1 November 2013 (PDT)

[edit] Request for clarification on setting state

The following situation are imho not properly documented here or require at least some clarification:

Reading (count-1) characters before encountering eof/delim results in the fail bit being set.

(Currently the only situation where setting the fail bit is documented is the case where no characters are extracted.)

indeed, it was missing https://eel.is/c++draft/istream.unformatted#18.3 - fixing --Cubbi (talk) 06:42, 8 June 2023 (PDT)