$\require{cancel}$
cin >> varName will
varName.
varName.
varName is a string.
\n ^ ____\t__Hello___\n
\n
____\t__Hello___\n
^
varName.
\n
____\t__Hello___\n
^
varName will now contain "Hello". And the next character in the input buffer is a space.
getline
getline(input stream, string identifier [, char delimiter])
string name
cout << "Enter your full name =>";
getline(cin, name);
Marry, Queen of Scots\n
^
next line\n
Marry, Queen of Scots\n
next line\n
^
name will contain Mary, Queen of Scots.
int n;
string s;
cout << "Enter a number =>";
cin >> n;
cout << "Enter a phrase =>";
getline(cin, s);
5\n
^
Marry, Queen of Scots\n
next line\n
5\n
Marry, Queen of Scots\n
^
next line\n
inputstream.ignore(int count, char delim)
count characters, including white space.
delim is encountered.
int n; string s; cout << "Enter a number =>"; cin >> n; cin.ignore(100, '\n'); cout << "Enter a phrase =>"; getline(cin, s);
cin.get() returns the next character, regardless of whitespace. It also advance the stream pointer.
cin.unget() backs the stream pointer up one character.