When you type characters and press Enter, they go into an input buffer. The cin >> operator reads from this buffer, skipping any leading whitespace (spaces, tabs, newlines) automatically.
If the buffer contains 42 (with leading spaces), cin >> x; skips those spaces and reads 42. The extraction stops at the next whitespace, leaving anything else in the buffer for the next read.
This automatic whitespace skipping works perfectly for numbers and single words. However, it creates problems when you want to read text with spaces, which I will show you later.