zoukankan      html  css  js  c++  java
  • C++ 中map 中迭代器的简单使用:

    public member function
    <map>

    std::map::find

          iterator find (const key_type& k);
    const_iterator find (const key_type& k) const;
    Get iterator to element

    Searches the container for an element with a key equivalent to k and returns an iterator to it if found, otherwise it returns an iterator to map::end.

    Two keys are considered equivalent if the container's comparison object returns false reflexively (i.e., no matter the order in which the elements are passed as arguments).

    Another member function, map::count, can be used to just check whether a particular key exists.

    Parameters

    k
    Key to be searched for.
    Member type key_type is the type of the keys for the elements in the container, defined in map as an alias of its first template parameter (Key).

    Return value

    An iterator to the element, if an element with specified key is found, or map::end otherwise.

    If the map object is const-qualified, the function returns a const_iterator. Otherwise, it returns an iterator.

    Member types iterator and const_iterator are bidirectional iterator types pointing to elements (of type value_type).
    Notice that value_type in map containers is an alias of pair<const key_type, mapped_type>.

    Example

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    // map::find
    #include <iostream>
    #include <map>
    
    int main ()
    {
      std::map<char,int> mymap;
      std::map<char,int>::iterator it;
    
      mymap['a']=50;
      mymap['b']=100;
      mymap['c']=150;
      mymap['d']=200;
    
      it = mymap.find('b');
      if (it != mymap.end())
        mymap.erase (it);
    
      // print content:
      std::cout << "elements in mymap:" << '
    ';
      std::cout << "a => " << mymap.find('a')->second << '
    ';
      std::cout << "c => " << mymap.find('c')->second << '
    ';
      std::cout << "d => " << mymap.find('d')->second << '
    ';
    
      return 0;
    }



    Output:

    elements in mymap:
    a => 50
    c => 150
    d => 200
    
  • 相关阅读:
    Burpsuite intruder模块 越过token进行爆破,包含靶场搭建
    burpsuiteb windows10 下载与安装
    sqlmap的命令总结
    Vue.js与jQuery混用
    IE低版本cors跨域请求
    window.open打开网址被拦截
    一图一知之python3数据类型
    一图一知-vue强大的slot
    一图一知-强大的js数组
    windows中git输错密码后不能修改问题
  • 原文地址:https://www.cnblogs.com/the-tops/p/5586848.html
Copyright © 2011-2022 走看看