Please ask me why cin. getline () dont receive string. | Sololearn: Learn to code for FREE!

+2

Please ask me why cin. getline () dont receive string.

https://code.sololearn.com/c868TYy9DjWH/?ref=app

c++

3/11/2021 4:24:03 PM

M. Jawahirullah

1 Answer

New Answer

+2

You must be entering input in separate lines, like this string-input integer-input another-string-input Because, cin.getline() does not trim the whitespaces in the input, it stops accepting input when it encounters a newline. See here http://www.cplusplus.com/reference/istream/istream/getline/ "The delimiting character is the newline character ('\n') for the first form" So in your code, after the integer is accepted, a newline is encountered and input ends there. Try giving input like this (separated by space) string-input int-input another-string-input Or, you can pass in another argument to cin.getline(), that is a character that would be used as delimiter. So for example cin.getline(str, 50, '.') would stop accepting input when '.' is encountered or there is no input left