title: how to remove duplicates (with original value) from a vector in c++
body: <p>I wrote the program to remove the duplicates from a given set of numbers. but i am not getting required output.Instead i am getting SIGSTP runtime error each time. input/output format is something like this:
        input: 1 2 5 7 1 4 2
        output: 5 7 4
  my code is given below:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include&lt;string&gt;
  #include &lt;vector&gt;
  using namespace std;
  
  int main() {
      // your code goes here
      int t;
      cin &gt;&gt; t;
      while(t--)
      {
          int n;
          cin &gt;&gt; n;
          vector&lt;int&gt; v_num;
          for(int i=0;i&lt;n;i++)
          {
              int x;
              cin &gt;&gt; x;
              v_num.push_back(x);
         }
         vector&lt;int&gt;::iterator it;
         for(it=v_num.begin();it!=v_num.end();)
         {
             int val=*it;
             int flag=0;
             vector&lt;int&gt;:: iterator j;
             for(j=it+1;j!=v_num.end();)
             {
                 if(val==*j)
                 {
                     v_num.erase(j);
                     flag=1;
                 }
                 if(flag==0)
                    j++;
             }
             if(flag==1)
                  { v_num.erase(it);
                   flag=1;}
             if(flag==0)
                   it++;
         }
  
          for(int i=0;i&lt;v_num.size();i++)
             { cout &lt;&lt;v_num[i]&lt;&lt;endl;
              }
      }
  
  }
  </code></pre>
  
  <p>it is my first question on online platform,so sometimes I may not be clear. In that case any suggestion or further clarification needed can be posted in comment section. Thanks in advance.</p>