c++关于map的find和count的使用

这几天读紫书真的是受益匪浅啊,每天都有新东西在学习,今天就留一个知识点...

编程的时候比较常用...

使用count,返回的是被查找元素的个数。如果有,返回1;否则,返回0。注意,map中不存在相同元素,所以返回值只能是1或0。

使用find,返回的是被查找元素的位置,没有则返回map.end()。

#include
#include
#include
#include
#include
#include
using namespace std;
int main(){
    map test;
    test.insert(make_pair("test1",1));//test["test1"]=1
    test.insert(make_pair("test2",2));//test["test2"]=2
    map::iterator it;
    it=test.find("test0");
    cout<<"test0 find:";
    if(it==test.end()){
        cout<<"test0 not found"<second<second<second<
c++关于map的find和count的使用_第1张图片

原博:http://www.cnblogs.com/Deribs4/p/4948351.html


你可能感兴趣的:(函数收集(C++))