STL-去除vector中重复的元素


// Test7.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include
#include
#include
int _tmain(int argc, _TCHAR* argv[])
{
std::vector singleValueVector;
singleValueVector.push_back("acid");
singleValueVector.push_back("acre");
singleValueVector.push_back("also");
singleValueVector.push_back("ache");
singleValueVector.push_back("ache");
singleValueVector.push_back("radio");
singleValueVector.push_back("able");
singleValueVector.push_back("ache");
singleValueVector.push_back("ache");
singleValueVector.push_back("acid");
singleValueVector.push_back("acre");
singleValueVector.push_back("auto");
singleValueVector.push_back("away");
singleValueVector.push_back("also");
singleValueVector.push_back("ache");
singleValueVector.push_back("ache");
singleValueVector.push_back("acid");
singleValueVector.push_back("acre");
singleValueVector.push_back("also");
sort(singleValueVector.begin(), singleValueVector.end());//sort the vector
singleValueVector.erase( unique( singleValueVector.begin(), singleValueVector.end() ), singleValueVector.end());//Remove duplicate vector values
return 0;
}



[color=red]

debug下处理后的vector的值:
singleValueVector[8]("able","ache","acid","acre","also","auto","away","radio")
[/color]

你可能感兴趣的:(C++学习笔记,STL)