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

📄 all.html

📁 从www.CppReference.com打包的C++参考手册
💻 HTML
📖 第 1 页 / 共 2 页
字号:
  </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><hr>  <div class="name-format">    lower_bound  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;map&gt;  iterator lower_bound( const <a href="../containers.html">key_type</a>&amp; key );</pre>  <p>The lower_bound() function returns an iterator to the first  element which has a value greater than or equal to key.</p>  <p>lower_bound() runs in <a href="../complexity.html">logarithmic  time</a>.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="upper_bound.html">upper_bound</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    Map Constructors &amp; Destructors  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;map&gt;  map();  map( const map&amp; m );  map( iterator start, iterator end );  map( iterator start, iterator end, const key_compare&amp; cmp );  map( const key_compare&amp; cmp );  ~map();</pre>  <p>The default constructor takes no arguments, creates a new instance  of that map, and runs in <a href="../complexity.html">constant  time</a>. The default copy constructor runs in <a href=  "../complexity.html">linear time</a> and can be used to create a new  map that is a copy of the given map <em>m</em>.</p>  <p>You can also create a map that will contain a copy of the  elements between <em>start</em> and <em>end</em>, or specify a  comparison function <em>cmp</em>.  <p>The default destructor is called when the map should be  destroyed.</p>  <p>For example, the following code creates a map that associates a  string with an integer:</p>  <pre class="example-code">  struct strCmp {    bool operator()( const char* s1, const char* s2 ) const {      return strcmp( s1, s2 ) &lt; 0;    }  };  ...  map&lt;const char*, int, strCmp&gt; ages;  ages["Homer"] = 38;  ages["Marge"] = 37;  ages["Lisa"] = 8;  ages["Maggie"] = 1;  ages["Bart"] = 11;  cout &lt;&lt; "Bart is " &lt;&lt; ages["Bart"] &lt;&lt; " years old" &lt;&lt; endl;</pre>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="map_operators.html">Map Operators</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    Map operators  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;map&gt;  <a href="../containers.html">TYPE</a>&amp; operator[]( const <a href="../containers.html">key_type</a>&amp; key );  map operator=(const map&amp; c2);  bool operator==(const map&amp; c1, const map&amp; c2);  bool operator!=(const map&amp; c1, const map&amp; c2);  bool operator&lt;(const map&amp; c1, const map&amp; c2);  bool operator&gt;(const map&amp; c1, const map&amp; c2);  bool operator&lt;=(const map&amp; c1, const map&amp; c2);  bool operator&gt;=(const map&amp; c1, const map&amp; c2);</pre>  <p>Maps can be compared and assigned with the standard comparison  operators: ==, !=, &lt;=, &gt;=, &lt;, &gt;, and =. Individual  elements of a map can be examined with the [] operator.</p>  <p>Performing a comparison or assigning one map to another takes  <a href="../complexity.html">linear time</a>.</p>  <p>Two maps are equal if:</p>  <ol>    <li>Their size is the same, and</li>    <li>Each member in location <em>i</em> in one map is equal to the    the member in location <em>i</em> in the other map.</li>  </ol>  <p>Comparisons among maps are done lexicographically.</p>  <p>For example, the following code defines a map between strings and  integers and loads values into the map using the [] operator:</p>  <pre class="example-code">  struct strCmp {    bool operator()( const char* s1, const char* s2 ) const {      return strcmp( s1, s2 ) &lt; 0;    }  };  map&lt;const char*, int, strCmp&gt; ages;  ages["Homer"] = 38;  ages["Marge"] = 37;  ages["Lisa"] = 8;  ages["Maggie"] = 1;  ages["Bart"] = 11;  cout &lt;&lt; "Bart is " &lt;&lt; ages["Bart"] &lt;&lt; " years old" &lt;&lt; endl;  cout &lt;&lt; "In alphabetical order: " &lt;&lt; endl;  for( map&lt;const char*, int, strCmp&gt;::iterator iter = ages.begin(); iter != ages.end(); iter++ ) {    cout &lt;&lt; (*iter).first &lt;&lt; " is " &lt;&lt; (*iter).second &lt;&lt; " years old" &lt;&lt; endl;  }</pre>  <p>When run, the above code displays this output:</p>  <pre class="example-code">  Bart is 11 years old  In alphabetical order:  Bart is 11 years old  Homer is 38 years old  Lisa is 8 years old  Maggie is 1 years old  Marge is 37 years old  </pre>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="insert.html">insert</a><br>    <a href="map_constructors.html">Map Constructors &amp; Destructors</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    max_size  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;map&gt;  <strong>size_type</strong> max_size() const;</pre>  <p>The max_size() function returns the maximum number of elements  that the map can hold. The max_size() function should not be confused  with the <a href="size.html">size</a>() or (C++ Strings) <a href=  "../cppstring/capacity.html">capacity</a>() functions, which return  the number of elements currently in the map and the the number of  elements that the map will be able to hold before more memory will  have to be allocated, respectively.</p>  <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">    rbegin  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;map&gt;  <a href="../iterators.html">reverse_iterator</a> rbegin();  const_<a href="../iterators.html">reverse_iterator</a> rbegin() const;</pre>  <p>The rbegin() function returns a <a href=  "../iterators.html">reverse_iterator</a> to the end of the current  map.</p>  <p>rbegin() 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="end.html">end</a><br>    <a href="rend.html">rend</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    rend  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;map&gt;  <a href="../iterators.html">reverse_iterator</a> rend();  const_<a href="../iterators.html">reverse_iterator</a> rend() const;</pre>  <p>The function rend() returns a <a href=  "../iterators.html">reverse_iterator</a> to the beginning of the  current map.</p>  <p>rend() 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="end.html">end</a><br>    <a href="rbegin.html">rbegin</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    size  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;map&gt;  <strong>size_type</strong> size() const;</pre>  <p>The size() function returns the number of elements in the current  map.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="empty.html">empty</a><br>    <a href="max_size.html">max_size</a><br>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    swap  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;map&gt;  void swap( container&amp; from );</pre>  <p>The swap() function exchanges the elements of the current map with  those of <em>from</em>. This function operates in <a href=  "../complexity.html">constant time</a>.</p>  <p>For example, the following code uses the swap() function to  exchange the values of two strings:</p>  <pre class="example-code">   string first( &quot;This comes first&quot; );   string second( &quot;And this is second&quot; );   first.swap( second );   cout &lt;&lt; first &lt;&lt; endl;   cout &lt;&lt; second &lt;&lt; endl;          </pre>  <p>The above code displays:</p>  <pre class="example-code">   And this is second   This comes first             </pre>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    (C++ Lists) <a href="../cpplist/splice.html">splice</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    upper_bound  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;map&gt;  iterator upper_bound( const <a href="../containers.html">key_type</a>&amp; key );</pre>  <p>The function upper_bound() returns an iterator to the first  element in the map with a key greater than <em>key</em>.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="lower_bound.html">lower_bound</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    value_comp  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;map&gt;  value_compare value_comp() const;</pre>  <p>The value_comp() function returns the function that compares  values.</p>  <p>value_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="key_comp.html">key_comp</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr></body></html>

⌨️ 快捷键说明

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