+ 2
Difference between getline(cin, str ,'\n'); And getline(cin, str);
6 Antworten
+ 13
getline (cin, str);
and
getline (cin, str, '\n');
both means the same thing. The third parameter specifies the delimitation character. When this character is met, the rest of the input will be ignored. The default delim for getline function is the newline character '\n'.
We actually have pretty legit official documentation! Please refer:
http://www.cplusplus.com/reference/string/string/getline/
+ 4
I have not used the first one you listed
Does it work?
+ 4
I saw not difference in the output.
Maybe because the whitespace of the newline was ignored.
+ 3
I does not seem work in the playground
https://code.sololearn.com/cp32oQ9205NP/?ref=app
+ 3
Oh,
I did not see @Hatsy's answer. 😸
+ 1
I think the first one adds the \n character to the end of the string while the next one just takes string as input and assigns it to str variable