I think the problem is that cin >>
passes on the newline character (\n)
. The getline() assumes the newline character is whitespace and passes it on. Someone posted a solution you can use.
You can use a dummy getline(cin, dummy);
or the real thing cin.ignore(100,'\n');