#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;
分享到:
相关推荐
主要面向初学者,简单介绍了容器Vector与map,简单易懂。
vector list map pair stl 标准模板库 c++ 程序示例
同时具备vecotor和map的特性
vec, map<int, int>& visited){... 9次阅读2019-12-20 11:40:50 友元函数 //友元函数:可以访问类的私有数据成员和私有函数。 友元函数声明有friend,但定义不需要。#include &lt;iostream&gt;#...
STL中vector、list、deque和map的区别
List、ArrayList、Vector及map、HashTable、HashMap分别的区别
Vector ASAP2Editor .map转.a2l 文件 附带使用说明 操作比较简单 测试可以正常安装 正常使用
高精度地图样本
in as it is an advanced and modified version of the vector Map plug-in that comes with in-built maps of the world. You can add various borders, colors and include opacities via the different ...
STL 中的常用的Vector Map Set Sort用法
便于学习MAP和vector的使用方法,通过代码可以看到迭代器的使用。
Java中List、ArrayList、Vector及map、HashTable、HashMap分别的区别.
C++ 利用MAP和VECTOR实现多节点树,VC++ 利用STL中的MAP和VECTOR实现的一个多节点树。
c程序必备的辅导材料,新手必需品,详细介绍了map,set的用法
Tunisia jQuery Vector MAP</title><link href="css/jqvmap.css" media="screen" rel="stylesheet" type="text/css" /><script src=...
主要介绍了C++中vector可以作为map的键值实例代码,需要的朋友可以参考下
ArrayList、LinkedList、 Vector、Map 用法比较
区别和联系-list-map-set-vector