How to remove duplicate vectors inside a multidimensional vector?

I have a vector of vectors:

vector< vector<int> > BigVec;

It contains an arbitrary number of vectors, each of which has an arbitrary size. I want to remove non-repeating elements of each vector, but any vectors that are exactly the same as the others. I do not need to keep the order of the vectors so that I can sort, etc.

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

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 this to work.

+3
source share
1 answer

? , , std::unique . , -

std::vector<std::vector<int>> myVec;
std::sort(myVec.begin(), myVec.end());
myVec.erase(std::unique(myVec.begin(), myVec.end()), myVec.end());
+6

Source: https://habr.com/ru/post/1738433/


All Articles