Does std::getline() empties the buffer completely or do we still have the newline character left in the input buffer?
Asked
Active
Viewed 142 times
1 Answers
4
As the page states:
If the delimiter is found, it is extracted and discarded (i.e. it is not stored and the next input operation will begin after it).
It should be discarded.
Check out this example. The newline in between the two sentences is appropriately discarded.
Answering to comment:
(1) istream& getline (istream& is, string& str, char delim);
(2) istream& getline (istream& is, string& str);
Extracts characters from is and stores them into str until the delimitation character delim is found (or the newline character, '\n', for (2)).
Yes, newline acts as the default delimiter.
No, the input buffer would not have the newline character in it anymore as it would be succinctly discarded. You don't need to clean by yourself.

Community
- 1
- 1

Saurav Sahu
- 13,038
- 6
- 64
- 79
-
I feel like I do understand what you're saying but just so there isn't ambiguity in my understanding let me ask this: If the delimiter is not found the newline character acts as a delimiter? Once the newline character is reached everything before is stored in the string, but now does the input buffer still have the newline character in it and I need to clean the buffer to get rid of it or no? – Hamza Khan Oct 23 '16 at 18:19