I read that cin terminates as soon as it sees a newline character or white space and it doesn't consume that and leaves it in the input buffer. Therefore, between cin and cin.getline() commands, we should add a cin.get() to consume the endline character. But if this is the case, how does two cin commands work? For eg:
int N;
int M;
cin>>N;
cin>>M;
Once we take the input of N and press enter, then a newline character must be left in the input stream. When we reach to line cin>>M, how does it work given that cin should terminate as the character in the input stream now is "\n".
Please help me resolve my confusion. I'd be glad to know how the input and output in C++ works.