#include <algorithm>
#include <map>
#include <vector>
//std::map在insert后是自动排序的,查找的时候可以使用 find
std::map<int,string> mapDemo_;
if(mapDemo_.find(nKey) != mapDemo_.end())
{
//find
}
//std::vector在push_back()后不会自动排序,可以使用sort进行排序
std:vector(int) vecDemo_;
sort(vecDemo.begin(),vecDemo_.end());
if(binary_search(vecDemo.begin(),vecDemo_.end(),nFindKey))
{
//find
}
//map的key和vector的value必须是重载过比较符的
typedef struct stKeyStrValue
{
unsigned int nKey;
string strValue;
int operator <(const stKeyStrValue &p)const
{
return ( this->nKey < p.nKey);
}
bool operator==(const unsigned int & nKey)const
{
return (this->nKey == nKey);
}
}SKeyStrValue;