#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
using namespace std;
int main(int argc, const char * argv[])
{
stringstream sentence("the quick red fox jumps over the slow red turtle");
string word;
vector<string> words;
while (sentence >> word)
{
words.push_back(word);
}
sort(words.begin(), words.end());
vector<string>::iterator unque_iter = unique(words.begin(), words.end());
words.erase(unque_iter, words.end());
return 0;
}
说明: unique()函数返回的是指向没有重复内容的下一个位置。而且其并不是删除其中的重复元素,只是将其移到容器的末尾,所以还需要自己待用erase()来彻底删除.
C++,unique(),erase,重复