The video on getline left me with a question. Perhaps the answer will go over my head but still I’d like to have something to grab onto. What exactly do the parameters for getline do?
I’m trying to explain it but I’m a noob, consider that…
Basically getline() is useful cause it simplify what you otherwise should do :
example : cin << Guess << endl; (this is what you did in the previous lesson.
Plus, using getline() is useful because it doesn’t stop the search of strings when it finds a space between string
example : if you write a name like donkey kong, in the console (as input) without getline() in the code, you’ll receive only donkey as result.
basically getline() search for strings until it reaches a \n (new line).
Hope this help and if I missed or wrote something wrong, please correct me.
Ciao
It helps to understand what a delimiter is.
In the function definition:
Extracts characters from is[input stream] and stores them into str[string] until the delimitation character delim[delimiter] is found (or the newline character, ‘\n’, for (2)).
When you input the text and press enter you are creating a delimiter (in this case ‘\n’ is created by pressing enter).
Once getline() is called it will set the guess string with your text and discard the newline character created by pressing ‘enter’.
Delimiters can become more complex, and I am sure you will come to understand them better as you progress.