Both formatted inputs, scanf and cin will leave stuff on the input buffer after they have consumed stuff from it, in your case that happens to be newline.
what is the solution, how can I take exact input as per the value of n?
it's simple, consume the newline character after scanf
I don't get it. even without the cout line after getline, it is taking 2 input despite n is 3. the newline is coming from enter key I guess
yeah, it was surprising to me too but i've never used getline() ever with cin so (_-_)
what should I use then to take string input which has whitespace?
Обсуждают сегодня