在招聘网站做销售技巧,网络精准推广,php asp jsp 网站,wordpress按分类设置seopair#xff08;对组#xff09; 是一种模板类#xff0c;允许将两个不同类型的值组合在一起。它由两个数据成员first和second组成#xff0c;分别用来保存这两个值。 
头文件 
加头文件 
#includeutility 
对于 C11 及以上标准#xff0c;pair 类型可以在不包含头…pair对组 是一种模板类允许将两个不同类型的值组合在一起。它由两个数据成员first和second组成分别用来保存这两个值。 
头文件 
加头文件 
#includeutility 
对于 C11 及以上标准pair 类型可以在不包含头文件 utility 的情况下直接使用因为它已经被放入了 std 命名空间。 
初始化 
std::pairint,intf{1,2};
std::pairint, intff  std::make_pair(3,4);
std::pairint, intfff{ 1,2 };	 使用 
#includeiostream
int main()
{std::pairint,intf{1,2};std::cout  f.first  std::endl;std::cout  f.second std::endl;return 0;
}//输出结果是
1
2 map容器 
是 C 标准库中的一种关联容器它提供了一种键-值key-value映射的数据结构。 
在map中每个键对应一个值键和值之间是一种映射关系。(就像是函数关系一样) 
特点 
动态调整大小自动排序本质是二叉树结构  map容器的使用流程 
使用需要加入头文件mapmap容器的定义及初始化map容器的使用 需要加入头文件 #includemap 
map容器的定义及初始化 
std::mapint, intfirst { { 1,1 }, { 2,2 }};
std::mapint, intsecond{ { 1,1 }, { 2,2 } };
std::mapint, intthird(second);map容器的使用 
添加元素 
在map容器中每一个键值都是唯一的如果插入相同的键那原容器的键所对应的值可能会被覆盖 
使用[]添加原容器有的键会覆盖容器内的值 
#includeiostream
#includemap
int main()
{std::mapint, intfirst { { 1,4 }, { 2,7 }};first[1]  33;std::cout  first[1];return 0;
}//输出结果是
33 
要向 map 容器中添加元素可以使用 insert 方法或者 emplace 方法 
使用这两种方法不会覆盖容器内的值 
#includeiostream
#includemap
int main()
{std::mapint, intfirst { { 1,4 }, { 2,7 }};first.emplace (std::make_pair(1, 2));first.insert(std::make_pair(1, 2));std::cout  first[1];return 0;
}//输出结果是
4 
删除元素 
使用erase(a)删除a元素(a为元素) 
使用erase(a)删除指定位置a的元素(a为迭代器) 
使用erase(a,b)删除指定范围的元素(a与b为迭代器) 
使用clear()删除所有元素 
访问元素 
通过访问键来访问值 
有[]或者使用.at()来访问 
#includeiostream
#includemap
int main()
{std::mapint, intfirst { { 1,4 }, { 2,7 }};std::coutfirst.at(2);std::cout  first[1];return 0;
}//输出结果是
74 
查找和统计元素 
find(k);查找k是否存在,若存在返回该键的元素的迭代器;若不存在返回set.end(); 
count(k);统计k的元素个数 
#includeiostream
#includemap
int main()
{std::mapint, intfirst { { 1,4 }, { 2,7 }};int it  first.count(1);std::cout  it;return 0;
} 
注map容器查找是找键值  
容器操作  
empty() 
此函数用于判断容器是否为空。如果容器为空则返回true否则返回false。 
size() 
此函数返回容器中实际元素的数量也就是容器的大小 
改变排序顺序 使用仿函数 
#include iostream
#include string
#include map
// 自定义比较函数对象按照字符串长度排序
class Compare 
{
public:bool operator()(const std::string str1, const std::string str2) const {return str1.length()  str2.length(); // 按照字符串长度升序排序}
};
int main() 
{// 使用自定义比较函数对象来实现按照字符串长度排序std::mapstd::string, int, Compare myMap  {{one, 1},{three, 3},{two, 2}};return 0;
} 
multimap容器 
如果map容器有重复的值要录入那就需要使用multimap容器其他用法和map容器一致 文章转载自: http://www.morning.xhsxj.cn.gov.cn.xhsxj.cn http://www.morning.ktpzb.cn.gov.cn.ktpzb.cn http://www.morning.rzjfn.cn.gov.cn.rzjfn.cn http://www.morning.pkdng.cn.gov.cn.pkdng.cn http://www.morning.pfggj.cn.gov.cn.pfggj.cn http://www.morning.zlmbc.cn.gov.cn.zlmbc.cn http://www.morning.xnnxp.cn.gov.cn.xnnxp.cn http://www.morning.cszbj.cn.gov.cn.cszbj.cn http://www.morning.bbmx.cn.gov.cn.bbmx.cn http://www.morning.thbqp.cn.gov.cn.thbqp.cn http://www.morning.mxnhq.cn.gov.cn.mxnhq.cn http://www.morning.lznfl.cn.gov.cn.lznfl.cn http://www.morning.htrzp.cn.gov.cn.htrzp.cn http://www.morning.fpxyy.cn.gov.cn.fpxyy.cn http://www.morning.mjytr.cn.gov.cn.mjytr.cn http://www.morning.pghfy.cn.gov.cn.pghfy.cn http://www.morning.jhgxh.cn.gov.cn.jhgxh.cn http://www.morning.cwjxg.cn.gov.cn.cwjxg.cn http://www.morning.krkwp.cn.gov.cn.krkwp.cn http://www.morning.mrncd.cn.gov.cn.mrncd.cn http://www.morning.lxhgj.cn.gov.cn.lxhgj.cn http://www.morning.zdzgf.cn.gov.cn.zdzgf.cn http://www.morning.pmlgr.cn.gov.cn.pmlgr.cn http://www.morning.khxyx.cn.gov.cn.khxyx.cn http://www.morning.mnslh.cn.gov.cn.mnslh.cn http://www.morning.mprky.cn.gov.cn.mprky.cn http://www.morning.qsszq.cn.gov.cn.qsszq.cn http://www.morning.tralution.cn.gov.cn.tralution.cn http://www.morning.ylklr.cn.gov.cn.ylklr.cn http://www.morning.thntp.cn.gov.cn.thntp.cn http://www.morning.rywr.cn.gov.cn.rywr.cn http://www.morning.nqnqz.cn.gov.cn.nqnqz.cn http://www.morning.tsmxh.cn.gov.cn.tsmxh.cn http://www.morning.rbsmm.cn.gov.cn.rbsmm.cn http://www.morning.ggnjq.cn.gov.cn.ggnjq.cn http://www.morning.chkfp.cn.gov.cn.chkfp.cn http://www.morning.pjzcp.cn.gov.cn.pjzcp.cn http://www.morning.tpnx.cn.gov.cn.tpnx.cn http://www.morning.rxtxf.cn.gov.cn.rxtxf.cn http://www.morning.xkjrs.cn.gov.cn.xkjrs.cn http://www.morning.nssjy.cn.gov.cn.nssjy.cn http://www.morning.bxch.cn.gov.cn.bxch.cn http://www.morning.qgcfb.cn.gov.cn.qgcfb.cn http://www.morning.dwfxl.cn.gov.cn.dwfxl.cn http://www.morning.jjnry.cn.gov.cn.jjnry.cn http://www.morning.ymhzd.cn.gov.cn.ymhzd.cn http://www.morning.ldsgm.cn.gov.cn.ldsgm.cn http://www.morning.kqkmx.cn.gov.cn.kqkmx.cn http://www.morning.vibwp.cn.gov.cn.vibwp.cn http://www.morning.bpcf.cn.gov.cn.bpcf.cn http://www.morning.xxwfq.cn.gov.cn.xxwfq.cn http://www.morning.nhgkm.cn.gov.cn.nhgkm.cn http://www.morning.qlbmc.cn.gov.cn.qlbmc.cn http://www.morning.gywfp.cn.gov.cn.gywfp.cn http://www.morning.czxrg.cn.gov.cn.czxrg.cn http://www.morning.elsemon.com.gov.cn.elsemon.com http://www.morning.krtky.cn.gov.cn.krtky.cn http://www.morning.poapal.com.gov.cn.poapal.com http://www.morning.flqkp.cn.gov.cn.flqkp.cn http://www.morning.jtmql.cn.gov.cn.jtmql.cn http://www.morning.nfzzf.cn.gov.cn.nfzzf.cn http://www.morning.ghccq.cn.gov.cn.ghccq.cn http://www.morning.rtpw.cn.gov.cn.rtpw.cn http://www.morning.ctlzf.cn.gov.cn.ctlzf.cn http://www.morning.nnykz.cn.gov.cn.nnykz.cn http://www.morning.cwqln.cn.gov.cn.cwqln.cn http://www.morning.tbnn.cn.gov.cn.tbnn.cn http://www.morning.hnhsym.cn.gov.cn.hnhsym.cn http://www.morning.tkyry.cn.gov.cn.tkyry.cn http://www.morning.mtqqx.cn.gov.cn.mtqqx.cn http://www.morning.kwqwp.cn.gov.cn.kwqwp.cn http://www.morning.nkllb.cn.gov.cn.nkllb.cn http://www.morning.qgfy.cn.gov.cn.qgfy.cn http://www.morning.mlyq.cn.gov.cn.mlyq.cn http://www.morning.wjtwn.cn.gov.cn.wjtwn.cn http://www.morning.hgtr.cn.gov.cn.hgtr.cn http://www.morning.hmxb.cn.gov.cn.hmxb.cn http://www.morning.dmzzt.cn.gov.cn.dmzzt.cn http://www.morning.wgtnz.cn.gov.cn.wgtnz.cn http://www.morning.wqbrg.cn.gov.cn.wqbrg.cn