c++ 中map 的find 用法

c++ 中map 的find 用法,第1张

用find函数来定位数据出现位置,它返回的一个迭代器,当数据出现时,它返回数据所在位置的迭代器,如果map中没有要查找的数据,它返回的迭代器等于end函数返回的迭代器,程序说明

#include

#include

#include

Using namespace std;

Int main()

{

Map mapStudent;

mapStudent.insert(pair(1, “student_one”));

mapStudent.insert(pair(2, “student_two”));

mapStudent.insert(pair(3, “student_three”));

map::iterator iter;

iter = mapStudent.find(1);

if(iter != mapStudent.end())

{

Cout<<”Find, the value is ”

}

Else

{

Cout<<”Do not Find”<

}

}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/789502.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-05
下一篇 2022-05-05

发表评论

登录后才能评论

评论列表(0条)

保存