Possible Duplicate:
Need help with getline()
I’m trying to use the getline function in conjunction with cin to get input from the keyboard but my code skips over the getline statement and instead proceeds to cin function below. Here is my code and a screenshot of what is happening.

void addmovie(ofstream& MovieContentsFile) {
string movieTitle;
int movieQuantity;
cout << " \n Add Movie Selected \n " << endl;
cout << "Please type in the movie title and press enter \n" << endl;
getline(cin,movieTitle, '\n');
cout << "Movie: " << movieTitle << "Please type in the amount of copies we have of this movie \n " << endl;
cin >> movieQuantity;
I’d appreciate an explanation of why this is happening and how I can avoid it in the future
cin >> somethingleaves the trailing newline in the buffer, which would be ignored by the nextcin >> something_else(presumably this is how you read the menu option). However,getlinegets everything up to and including the next newline in the buffer, not ignoring whitespace. I.e. it gets nothing in this case (well, just the newline character).Generally it’s best not to mix use of both, it can get kinda messy.
Edit: To clarify,
getlinewill remove that last newline from the buffer, but won’t store it in yourstring.