title: Debug assertion failed.. C++ vector subscript out of range
body: <p>The following code is supposed to remove the duplicate values in a vector.<br>
  For example, if vector contains <code>{1,5,3,3}</code> the result should be <code>{1,5,3}</code>.</p>
  
  <p>The program starts and I enter the integer <code>n*</code>. 
  However, the program throws the following error:</p>
  
  <blockquote>
    <p>Debug assertion failed.Program : ...\include\vector line:932
    Expression:vector subscript out of range.</p>
  </blockquote>
  
  <p>When I press retry, visual c++ displays a new window:</p>
  
  <blockquote>
    <p>"try.exe has triggered a breakpoint".</p>
  </blockquote>
  
  <p>Then, after I click on continue, another error appears: </p>
  
  <blockquote>
    <p>Debug Assertion Failed! Program :...\include\vector line:933
    expression:"standart c++ libraries out of range" &amp;&amp; 0</p>
  </blockquote>
  
  <p>My code is as follows:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  using namespace std;
  void removeDup (vector&lt;int&gt;&amp; v);
  
  int main()
  {
      vector&lt;int&gt; v;
      int i,n;
      cin&gt;&gt;n;
      for(i=0;i&lt;n;i++){
          v[i]=rand()%10;
      }
      removeDup(v);
      for(i=0;i&lt;n;i++)
      {
          cout&lt;&lt;v[i];    
      }
      system("pause");
  }
  
  void removeDup(vector&lt;int&gt;&amp; v)
  {
      int i,j,size;
      size=v.size();
      for(i=0;i&lt;size;i++)
      {
          for(j=0;j&lt;size;j++)
          {
              if(v[i]==v[j])
              v.erase(v.begin()+j);
          }
      }
  }
  </code></pre>