title: c++ why is there still input buffer left?
body: <p>After my first entry, my second entery <code>name</code> field fills up with the input buffer from the previous entry. Why? I am even using the <code>getline</code> but the problem still persists. Please help me with the problem. This is question from <em>Jumping Into C++</em> book  .</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  struct Person
  {
      string name;
      string address;
      long long int PhoneNumber;
  };
  
  void displayEntries(Person p[])
  {
      int enteryNumber;
      cout &lt;&lt; "Enter the entry number of the person for details(enter 0 to display all entries): ";
      cin &gt;&gt; enteryNumber;
      if(enteryNumber == 0)
      {
          for(int i = 0; i &lt; 10; i++)
          {
              cout &lt;&lt; "Entery Number: " &lt;&lt; i + 1;
              cout &lt;&lt; "Name: " &lt;&lt; p[i].name &lt;&lt; endl;
              cout &lt;&lt; "Address: " &lt;&lt; p[i].address &lt;&lt; endl;
              cout &lt;&lt; "Phone Number: " &lt;&lt; p[i].PhoneNumber &lt;&lt; endl;
          }
      }
      do
      {
          cout &lt;&lt; "Entery Number: " &lt;&lt; enteryNumber;
          cout &lt;&lt; "Name: " &lt;&lt; p[enteryNumber].name &lt;&lt; endl;
          cout &lt;&lt; "Address: " &lt;&lt; p[enteryNumber].address &lt;&lt; endl;
          cout &lt;&lt; "Phone Number: " &lt;&lt; p[enteryNumber].PhoneNumber &lt;&lt; endl;
      } while (enteryNumber != 0);
  }
  
  int main()
  {
      Person p[10];
      for(int i = 0; i &lt; 10; i++)
      {
          cout &lt;&lt; "Enter the details of the person\n\n";
          cout &lt;&lt; "Name: ";
          getline(cin, p[i].name);
          cout &lt;&lt; "Address: ";
          getline(cin, p[i].address);
          cout &lt;&lt; "Phone Number: ";
          cin &gt;&gt; p[i].PhoneNumber;
          cout &lt;&lt; endl;
      }
      displayEntries(p);
      return 0;
  }
  </code></pre>