title: How to find the first smaller element than an integer X in a vector ? (c++)
body: <p>If I have the following vector {10 10 10 20 20 20 30 30}
  and I want a function to return the position of the integer that = X or directly the smaller element after X , like for example if I am searching for 11 I want the function to return 2 since the 2nd element(10) is the first smaller element than 11 in the vector.<br /> I tried using lower_bound but that doesn't work.</p>
  
  <pre><code>int myints[] = {10,20,30,30,20,10,10,20};
  vector&lt;int&gt; v(myints,myints+8);           // 10 20 30 30 20 10 10 20
  vector&lt;int&gt;::iterator low,up;
  
  sort (v.begin(), v.end());                // 10 10 10 20 20 20 30 30
  
  low=lower_bound (v.begin(), v.end(), 11); //
  up= upper_bound (v.begin(), v.end(), 11); //
  
  cout &lt;&lt; "lower_bound at position " &lt;&lt; int(low- v.begin()) &lt;&lt; endl;
  cout &lt;&lt; "upper_bound at position " &lt;&lt; int(up - v.begin()) &lt;&lt; endl;
  
  return 0;
  </code></pre>
  
  <p>this code outputs: <br /></p>
  
  <pre><code>lower_bound at position 3
  upper_bound at position 3
  </code></pre>