junk left in cin buffer
<p>i need to prevent the junk left in the buffer as entering a value for a switch case menu from being used in a function called by the menu where their is user input.</p>

<p>menu code</p>

<pre><code>void menu()
{
bool done = false; 
string input;
while(!done)
{
    cout &lt;&lt; "Welcome to the DVD database." &lt;&lt; endl;
    cout &lt;&lt; "1. Add A DVD" &lt;&lt; endl;
    cout &lt;&lt; "2. Delete a DVD." &lt;&lt; endl;
    cout &lt;&lt; "3. Edit a DVD." &lt;&lt; endl;
    cout &lt;&lt; "4. List By Category." &lt;&lt; endl;
    cout &lt;&lt; "5. Retrieve by a DVD by Title." &lt;&lt; endl;
    cout &lt;&lt; "6. Display collection by year" &lt;&lt; endl;
    cout &lt;&lt; "7. Display collection by title" &lt;&lt; endl;
    cout &lt;&lt; "-999. Exit program" &lt;&lt; endl;
    cout &lt;&lt; "Please choose an option by entering the corresponding number" &lt;&lt; endl;
    cin &gt;&gt; input;
    int value = atoi(input.c_str());
    switch(value)
    {
        case 1:addDVD(); break;
        case 2:deleteDVD(); break;
       // case 3:editDVD(); break;
        case 4:listByCategory();break;
        case 6:displayByYear();break;
        case 7:displayByTitle();break;
        case -999: writeToFile(); exit(0); break;
        default : cout &lt;&lt;"Invalid entry"&lt;&lt; endl; break;
    }
}
}

void retrieveByTitle()
{
string search;
int size = database.size();
int index = 0;
bool found = false;
cin.ignore();
cout &lt;&lt; "Please enter the title of the DVD you would like to retrieve: " &lt;&lt; endl;
getline(cin,search);
cout &lt;&lt; search;
while(!found &amp;&amp; index&lt;size)
{
    if(database.at(index)-&gt;getTitle().compare(search)==0)
    {
        cout &lt;&lt; database.at(index)-&gt;toString();
        break;
    }
}
cout &lt;&lt; endl;
}
</code></pre>

<p>if 5 is entered in the menu, the program skips the user input in the method</p>
