title: cin / cout being skipped
body: <p>I've been writing a sample program to compare runtimes of some algorithms, and this one has been causing me some trouble. For some reason, cin / cout is randomly skipped at various parts throughout the program, and I'm not entirely certain as to why. Here's the code, with the offending lines commented. find_element has been commented out for debugging, but doesn't work either. Any advice would be great!</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  void sort_vect( vector&lt; int &gt;&amp; );
  // int find_element( vector&lt; int &gt; );
  void print_vect( vector&lt; int &gt; );
  
  int main()
  {
      vector&lt; int &gt; int_vect;
      int input;
      int result;
  
      char garbage;
  
      cout &lt;&lt; "Enter a number into the vector (Q to quit) &gt; ";
  
      while(cin &gt;&gt; input &amp;&amp; input != 'Q' &amp;&amp; input != 'q')
      {
          int_vect.push_back(input);
          cout &lt;&lt; "&gt; ";
      }
  
      // The following doesn't help
      // cin &gt;&gt; garbage;
      // cout &lt;&lt; "Garbage : " &lt;&lt; garbage &lt;&lt; endl;
  
      if (int_vect.size() == 0)
      {
          cout &lt;&lt; "Vector empty" &lt;&lt; endl;
          return 1;
      }
  
      sort_vect(int_vect);
      print_vect(int_vect);
  
      cout &lt;&lt; "What value do you want &gt; ";
      cin &gt;&gt; input;   
  
      cout &lt;&lt; "Result : " &lt;&lt; int_vect[input-1] &lt;&lt; endl;
  
      return 0;
  } // main()
  
  void sort_vect( vector&lt; int &gt;&amp; int_vect)
  {
      vector&lt; int &gt;::iterator vect_iterator;
      vector&lt; int &gt;::iterator temp_iterator;
  
      int temp_store = NULL;
  
      for(vect_iterator = int_vect.begin(); vect_iterator != int_vect.end(); vect_iterator++)
      {
          for (temp_iterator = vect_iterator; temp_iterator != int_vect.begin(); temp_iterator--)
          {
              while(*temp_iterator &lt; *(temp_iterator-1))
              {
                  temp_store = *temp_iterator;
                  *temp_iterator = *(temp_iterator-1);
                  *(temp_iterator-1) = temp_store;
              }
          }
      }
  
      cout &lt;&lt; "Vector sorted." &lt;&lt; endl &lt;&lt; endl;
  }
  
  // int find_element( vector&lt; int &gt; int_vect)
  // {
  //  int input;
  //  char garbage;
  //  
  //  cout &lt;&lt; "Enter value to be returned (5 = 5th smallest) &gt; ";
  //  cin &gt;&gt; input;
  //  cout &lt;&lt; "Value for input : " &lt;&lt; input &lt;&lt; endl;
  //      
  //  return int_vect[input-1];
  // }
  
  void print_vect( vector&lt; int &gt; int_vect )
  {
      vector&lt; int &gt;::iterator vect_iterator = int_vect.begin();
  
      while(vect_iterator != int_vect.end())
      {
          cout &lt;&lt; *vect_iterator &lt;&lt; endl;
          vect_iterator++;
      }
  } // print_vect()
  </code></pre>
  
  <p>As per request, the output (Note : input is wrong as I forgot to properly use the input as an index, but that's not the problem at the moment) : </p>
  
  <pre><code>Enter a number into the vector (Q to quit) &gt; 1
  &gt; 2
  &gt; 4
  &gt; 6
  &gt; 5
  &gt; 3
  &gt; 4
  &gt; q
  Vector sorted.
  
  1
  2
  3
  4
  4
  5
  6
  What value do you want &gt; Result : 4
  </code></pre>