I have this function:

void read(){
    int id;
    string desc;
    string title, type;
    cout<<"Movie's id: ";
    cout<<"Movie's title: ";
    cout<<"Movie's description: ";
    getline(cin, desc, '\n');
    cout<<"Movie's type: ";
    cout<<"You have typed in: "
        <<" "
        <<" "
        <<" "

and my problem is that in the desc field, when I must insert something, it skips over, passing to the type field, not letting me insert anything. I've tried in another project only with the getline(cin, desc, '\n') and it worked, it took all the line, but here it just skips the field. My question is this: why does this thing happens? and did I do something wrong?

Edited 4 Years Ago by Lucaci Andrew

Sounds like another thread of the perils of mixing cin and getline. See this thread.


After line 8, there's an extra '\n' in the input stream. Line 10 gobbles that up and doesn't pause. Whenever you use getline immediately after cin with the >> operator, you need to get rid of thyat extra '\n' in the cin stream. See the ignore command here.


Stick this line right after line 8.

cin.ignore(256, '\n'); // 256 is just a big number.  Gobbles  up the rest of the line so that when you get to getline, you'll pause for input
This question has already been answered. Start a new discussion instead.