Extracts characters from stream until end of line or the specified delimiter delim.
The first overload is equivalent to getline(s, count, widen('\n')).
Behaves as UnformattedInputFunction. After constructing and checking the sentry object, extracts characters from *this and stores them in successive locations of the array whose first element is pointed to by s, until any of the following occurs (tested in the order shown):
basic_istream::get()
) and counted towards gcount(), but is not stored.If the function extracts no characters, âfailbit
is set in the local error state before setstate() is called.
In any case, if count > 0, it then stores a null character CharT() into the next successive location of the array and updates gcount().
[edit] NotesBecause condition #2 is tested before condition #3, the input line that exactly fits the buffer does not trigger failbit
.
Because the terminating character is counted as an extracted character, an empty input line does not trigger failbit
.
*this
[edit] Exceptionsfailureif an error occurred (the error state flag is not
goodbit) and
exceptions()is set to throw for that state.
If an internal operation throws an exception, it is caught and badbit is set. If exceptions() is set for badbit
, the exception is rethrown.
#include <array> #include <iostream> #include <sstream> #include <vector> int main() { std::istringstream input("abc|def|gh"); std::vector<std::array<char, 4>> v; // note: the following loop terminates when std::ios_base::operator bool() // on the stream returned from getline() returns false for (std::array<char, 4> a; input.getline(&a[0], 4, '|');) v.push_back(a); for (auto& a : v) std::cout << &a[0] << '\n'; }
Output:
[edit] Defect reportsThe following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior LWG 531 C++98std::getline
could not handle the
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4