当前位置:   article > 正文

c++ std::map find 用法

std::map find

用find函数来定位数据出现位置,它返回的一个迭代器,

  • 当数据出现时,它返回数据所在位置的迭代器,
  • 如果map中没有要查找的数据,它返回的迭代器等于end函数返回的迭代器

#include <map>

#include <string>

#include <iostream>

Using namespace std;

Int main()

{

       Map<int, string> mapStudent;

       mapStudent.insert(pair<int, string>(1, “student_one”));

       mapStudent.insert(pair<int, string>(2, “student_two”));

       mapStudent.insert(pair<int, string>(3, “student_three”));

       map<int, string>::iterator iter;

       iter = mapStudent.find(1);

        if(iter != mapStudent.end())

        {

               Cout<<”Find, the value is ”<<iter->second<<endl;

        }

        Else

        {

               Cout<<”Do not Find”<<endl;

        }

}

https://blog.csdn.net/qq_33573235/article/details/80277424

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/992034?site
推荐阅读
相关标签
  

闽ICP备14008679号