goktug96 goktug96 - 1 year ago 155
C++ Question

Task of getline

function can takes three parameters. First of them is the object
. Second of them is the object defined with the class
. Third of them is delimiter character.

1) If the delimiter character is not found, what happens?

2) For example, I chose character
for delimiter.Then, the user entered
. Does
remain in buffer or
remain in buffer? (I read that
deletes newline in buffer in every time although delimiter is not newline character but I do not ensure this.)

Answer Source

This is documented in std::getline

2) Extracts characters from input and appends them to str until one of the following occurs (checked in the order listed)
a) end-of-file condition on input, in which case, getline sets eofbit.
b) the next available input character is delim, as tested by Traits::eq(c, delim), in which case the delimiter character is extracted from input, but is not appended to str.

In the case of std::getline(std::cin, str, 't');, this means str will contain Jona, t will be extracted and discarded, keeping han\n in the input buffer.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download