-3

可能重复:
在 C++ 中的向量向量上使用“unique()”

我正在尝试对向量上的向量使用唯一算法。

我面临的错误是“独特的不能用作函数”

问题是即使使用 int 的法线向量,我也无法使用命令 unique()。

我正在尝试做的事情是擦除向量中的每个重复向量。

所以:

#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());

}

然后我会擦除从 itr 到向量末尾的所有其他项目

我究竟做错了什么?

4

1 回答 1

1

要么你没有正确的包含,要么你错过了std::某个地方。这个例子编译得很好:

#include <algorithm>
#include <vector>

int main()
{
  using std::vector;
  using std::unique;
  vector<vector<int> > v_main;
  v_main.push_back(vector<int>(10));
  v_main.push_back(vector<int>(10, 5));
  v_main.push_back(vector<int>(10, 6));
  vector<vector<int> >::iterator itr = unique(v_main.begin(), v_main.end());
}
于 2012-12-09T19:54:29.477 回答