getline function skipping

I'm trying to use the getline function to get a string with spaces but it only gets a newline and skips the prompt.

Here is the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
while ( 1 )
{
    cout << "\nEnter a command: ";
    cin >> command;
...
    // add a game
    else if ( command == "add" )
    {
        string newgame;
        cout << "Enter the game to add: ";
        getline( cin, newgame );
        games.push_back( newgame );
    }
}


So what happens is I get the prompt "Enter a command: ", I enter "add", It outputs "Enter the game to add: \nEnter a command: ".

Can anybody help me get this to behave the way I want it to?
Thank you for your help in advance.
I almost never code console apps, but if I remember correctly, you experience this because your line #4 over there is leaving the new line char in the buffer. To correct, use getline() as well to retrieve the command.
Cool! It worked.

Thanks webJose for the prompt response.
Topic archived. No new replies allowed.