Possible Duplicate:
Using “unique()” on a vector of vectors in C++
I’m trying to use the unique algorithm on a vector on vectors.
The error I’m facing is ” unique cannot be used as a function”
The problem is that I can’t use the command unique() even with normal vectors of int.
The thing I’m trying to do is to erase every repeated vector inside a vector.
so:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
void resettaPuntatore(int puntatore, int lunghezza)
{
puntatore = lunghezza;
}
int main()
{
vector<int> v_main;
vector<int> v_reverse;
vector<vector<int> > v_contenitore;
string parola;
int lunghezza_parola;
int puntatore;
cout << "Inserire la parola da permutare.\n";
cin >> parola;
lunghezza_parola = parola.length();
puntatore = lunghezza_parola-1;
for(int i = 0; i < lunghezza_parola; i++)
{
v_main.push_back(i+1);
}
for(int i = 0; i < lunghezza_parola; i++)
{
v_reverse.push_back(v_main[lunghezza_parola-1-i]);
}
while(v_main != v_reverse)
{
v_main[puntatore]++;
if(v_main[puntatore] > lunghezza_parola)
{
v_main[puntatore] = 1;
puntatore--;
}
else
{
resettaPuntatore(puntatore, lunghezza_parola);
}
v_contenitore.push_back(v_main);
}
vector<vector<int> >::iterator itr = unique(v_main.begin(), v_main.end());
}
And then I would erase all the other items from itr to the end of the vector
What am I doing wrong?
Either you don’t have the right includes, or you are missing an
std::somewhere. This example compiles fine: