📄 map_constructors.html
字号:
<!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>Map Constructors & Destructors</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> > <a href= "index.html">C++ Maps</a> > <a href= "map_constructors.html">Map Constructors & Destructors</a> </div> <div class="name-format"> Map Constructors & Destructors </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <map> map(); map( const map& m ); map( iterator start, iterator end ); map( iterator start, iterator end, const key_compare& cmp ); map( const key_compare& 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 ) < 0; } }; ... map<const char*, int, strCmp> ages; ages["Homer"] = 38; ages["Marge"] = 37; ages["Lisa"] = 8; ages["Maggie"] = 1; ages["Bart"] = 11; cout << "Bart is " << ages["Bart"] << " years old" << 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>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -