⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 all.html

📁 从www.CppReference.com打包的C++参考手册
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>  <meta name="generator" content=  "HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org">  <title>C++ Multimaps</title>  <link href="../cppreference.css" rel="stylesheet" type="text/css"></head><body><table>  <tr>  <td>  <div class="body-content">  <div class="header-box">    <a href="../index.html">cppreference.com</a> &gt; <a href=    "index.html">C++ Multimaps</a>  </div>  <div class="name-format">    begin  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;map&gt;  iterator begin();  const_iterator begin() const;</pre>  <p>The function begin() returns an iterator to the first element of  the multimap. begin() should run in <a href=  "../complexity.html">constant time</a>.</p>  <p>For example, the following code uses begin() to initialize an  iterator that is used to traverse a list:</p>  <pre class="example-code">   // Create a list of characters   list&lt;char&gt; charList;   for( int i=0; i &lt; 10; i++ ) {     charList.push_front( i + 65 );   }   // Display the list   list&lt;char&gt;::iterator theIterator;   for( theIterator = charList.begin(); theIterator != charList.end(); theIterator++ ) {     cout &lt;&lt; *theIterator;   }            </pre>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="end.html">end</a><br>    <a href="rbegin.html">rbegin</a><br>    <a href="rend.html">rend</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    clear  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;map&gt;  void clear();</pre>  <p>The function clear() deletes all of the elements in the multimap.  clear() runs in <a href="../complexity.html">linear time</a>.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    (C++ Lists) <a href="../cpplist/erase.html">erase</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    count  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;map&gt;  <strong>size_type</strong> count( const <a href="../containers.html">key_type</a>&amp; key );</pre>  <p>The function count() returns the number of occurrences of  <em>key</em> in the multimap.</p>  <p>count() should run in <a href="../complexity.html">logarithmic  time</a>.</p>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    empty  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;map&gt;  bool empty() const;</pre>  <p>The empty() function returns true if the multimap has no elements,  false otherwise.</p>  <p>For example, the following code uses empty() as the stopping  condition on a (C/C++ Keywords) <a href=  "../keywords/while.html">while</a> loop to clear a multimap and  display its contents in reverse order:</p>  <pre class="example-code"> vector&lt;int&gt; v; for( int i = 0; i &lt; 5; i++ ) {   v.push_back(i); } while( !v.empty() ) {   cout &lt;&lt; v.back() &lt;&lt; endl;   v.pop_back(); }              </pre>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="size.html">size</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    end  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;map&gt;  iterator end();  const_iterator end() const;</pre>  <p>The end() function returns an iterator just past the end of the  multimap.</p>  <p>Note that before you can access the last element of the multimap  using an iterator that you get from a call to end(), you&#39;ll have  to decrement the iterator first.</p>  <p>For example, the following code uses <a href=  "begin.html">begin</a>() and end() to iterate through all of the  members of a vector:</p>  <pre class="example-code"> vector&lt;int&gt; v1( 5, 789 ); vector&lt;int&gt;::iterator it; for( it = v1.begin(); it != v1.end(); it++ ) {   cout &lt;&lt; *it &lt;&lt; endl; }              </pre>  <p>The iterator is initialized with a call to <a href=  "begin.html">begin</a>(). After the body of the loop has been  executed, the iterator is incremented and tested to see if it is  equal to the result of calling end(). Since end() returns an iterator  pointing to an element just after the last element of the vector, the  loop will only stop once all of the elements of the vector have been  displayed.</p>  <p>end() runs in <a href="../complexity.html">constant time</a>.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="begin.html">begin</a><br>    <a href="rbegin.html">rbegin</a><br>    <a href="rend.html">rend</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    equal_range  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;map&gt;  pair&lt;iterator, iterator&gt; equal_range( const <a href="../containers.html">key_type</a>&amp; key );</pre>  <p>The function equal_range() returns two iterators - one to the  first element that contains <em>key</em>, another to a point just  after the last element that contains <em>key</em>.</p>  <p>For example, here is a hypothetical input-configuration loader  using multimaps, strings and equal_range():</p>    <pre class="example-code">  multimap&lt;string,pair&lt;int,int&gt; &gt; input_config;    // read configuration from file "input.conf" to input_config  readConfigFile( input_config, "input.conf" );     pair&lt;multimap&lt;string,pair&lt;int,int&gt; &gt;::iterator,multimap&lt;string,pair&lt;int,int&gt; &gt;::iterator&gt; ii;  multimap&lt;string,pair&lt;int,int&gt; &gt;::iterator i;    ii = input_config.equal_range("key");         // keyboard key-bindings  // we can iterate over a range just like with begin() and end()    for( i = ii.first; i != ii.second; ++i ) {    // add a key binding with this key and output    bindkey(i->second.first, i->second.second);   }  ii = input_config.equal_range("joyb");        // joystick button key-bindings  for( i = ii.first; i != ii.second; ++i ) {    // add a key binding with this joystick button and output    bindjoyb(i->second.first, i->second.second);  }  </pre>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    erase  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;map&gt;  void erase( iterator pos );  void erase( iterator start, iterator end );  <strong>size_type</strong> erase( const <a href="../containers.html">key_type</a>&amp; key );</pre>  <p>The erase function() either erases the element at <em>pos</em>,  erases the elements between <em>start</em> and <em>end</em>, or  erases all elements that have the value of <em>key</em>.</p>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    find  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;map&gt;  iterator find( const <a href="../containers.html">key_type</a>&amp; key );</pre>  <p>The find() function returns an iterator to <em>key</em>, or an  iterator to the end of the multimap if <em>key</em> is not found.</p>  <p>find() runs in <a href="../complexity.html">logarithmic  time</a>.</p>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    insert  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;map&gt;  iterator insert( iterator pos, const <a href="../containers.html">TYPE</a>&amp; val );  iterator insert( const <a href="../containers.html">TYPE</a>&amp; val );  void insert( <a href="../iterators.html">input_iterator</a> start, <a href="../iterators.html">input_iterator</a> end );</pre>  <p>The function insert() either:</p>  <ul>    <li>inserts <em>val</em> after the element at <em>pos</em> (where    <em>pos</em> is really just a suggestion as to where <em>val</em>    should go, since multimaps are ordered), and returns an iterator    to that element.</li>    <li>inserts <em>val</em> into the multimap, returning an iterator    to the element inserted.</li>    <li>inserts a range of elements from <em>start</em> to    <em>end</em>.</li>  </ul>  <p>For example, the following code uses the insert() function to add  several &lt;name,ID&gt; pairs to a employee multimap:</p>  <pre class="example-code">  multimap&lt;string,int&gt; m;  int employeeID = 0;  m.insert( pair&lt;string,int&gt;("Bob Smith",employeeID++) );  m.insert( pair&lt;string,int&gt;("Bob Thompson",employeeID++) );  m.insert( pair&lt;string,int&gt;("Bob Smithey",employeeID++) );  m.insert( pair&lt;string,int&gt;("Bob Smith",employeeID++) );  cout &lt;&lt; "Number of employees named 'Bob Smith': " &lt;&lt; m.count("Bob Smith") &lt;&lt; endl;  cout &lt;&lt; "Number of employees named 'Bob Thompson': " &lt;&lt; m.count("Bob Thompson") &lt;&lt; endl;  cout &lt;&lt; "Number of employees named 'Bob Smithey': " &lt;&lt; m.count("Bob Smithey") &lt;&lt; endl;  cout &lt;&lt; "Employee list: " &lt;&lt; endl;  for( multimap&lt;string, int&gt;::iterator iter = m.begin(); iter != m.end(); ++iter ) {    cout &lt;&lt; " Name: " &lt;&lt; iter-&gt;first &lt;&lt; ", ID #" &lt;&lt; iter-&gt;second &lt;&lt; endl;  }</pre>  <p>When run, the above code produces the following output:</p>  <pre class="example-code">  Number of employees named 'Bob Smith': 2  Number of employees named 'Bob Thompson': 1  Number of employees named 'Bob Smithey': 1  Employee list:   Name: Bob Smith, ID #0   Name: Bob Smith, ID #3   Name: Bob Smithey, ID #2   Name: Bob Thompson, ID #1</pre>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    key_comp  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;map&gt;  key_compare key_comp() const;</pre>  <p>The function key_comp() returns the function that compares  keys.</p>  <p>key_comp() runs in <a href="../complexity.html">constant  time</a>.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="value_comp.html">value_comp</a>  </div>  </div>  </td>    </tr>  </table></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -