How to delete duplicate vectors within a multidimensional vector?

Posted by David on Stack Overflow See other posts from Stack Overflow or by David
Published on 2010-03-25T03:54:10Z Indexed on 2010/03/25 4:03 UTC
Read the original article Hit count: 378

I have a vector of vectors:

vector< vector<int> > BigVec;

It contains an arbitrary number of vectors, each of an arbitrary size. I want to delete not duplicate elements of each vector, but any vectors that are the exact same as another. I don't need to preserve the order of the vectors so I can sort etc..

It should be a really simple problem to solve but I'm new to this, my (not-working) best effort:

for (int i = 0; i < BigVec.size(); i++)
  {
     for (int j = 1; j < BigVec.size() ; j++ )
        {
             if (BigVec[i][0] == BigVec [j][i]);
             {
                BigVec.erase(BigVec.begin() + j);
                i = 0;       // because i get the impression deleting a 
                j = 1;       // vector messes up a simple iteration through
             }
        }
  }

I think there might be a solution using Unique(), but I can't get that to work either.

© Stack Overflow or respective owner

Related posts about c++

Related posts about vector