📄 map.htm
字号:
<html>
<head>
<title> The map Class</title>
</head>
<body bgcolor="#FFFFFF">
<img src="mapban.gif">
<pre>
<font size=5>Class Name</font> map
<font size=5>Header File</font> <map>
<font size=5>Classification</font> container
</pre>
<a href="map.htm#desc">Class Description</a><br>
<h1>Member Classes</h1>
<i>None</i>
<h1>Methods</h1>
<pre>
<a href="common.htm#begin">iterator begin()</a><br>
<a href="common.htm#begin">const_iterator begin() const</a><br>
<a href="list.htm#clear">void clear()</a><br>
<a href="assoc.htm#count">size_type count(const key_type& x) const</a><br>
<a href="common.htm#empty">bool empty() const</a><br>
<a href="common.htm#end">iterator end()</a><br>
<a href="common.htm#end">const_iterator end() const</a><br>
<a href="assoc.htm#erase1">void erase(iterator position)</a><br>
<a href="assoc.htm#erase2">size_type erase(const key_type& x)</a><br>
<a href="assoc.htm#erase3">void erase(iterator first, iterator last)</a><br>
<a href="assoc.htm#equal">pair<iterator,iterator> equal_range(const key_type& x) const</a><br>
<a href="assoc.htm#find1">iterator find(const key_type& x) const</a><br>
<a href="assoc.htm#find1">const_iterator find(const key_type& x) const</a><br>
<a href="list.htm#getallocator">allocator_type get_allocator() const</a><br>
<a href="assoc.htm#insert1">pair<iterator,bool> insert(const value_type& x)</a><br>
<a href="assoc.htm#insert2">iterator insert(iterator position, const value_type& x)</a><br>
<a href="assoc.htm#insert3">template <class InputIterator>void insert(InputIterator first, InputIterator last)</a><br>
<a href="assoc.htm#lower">iterator lower_bound(const key_type& x) const</a><br>
<a href="assoc.htm#lower">const_iterator lower_bound(const key_type& x) const</a><br>
<a href="map.htm#map1">explicit map(const Compare& comp = Compare(), const Allocator& = Allocator())</a><br>
<a href="map.htm#map2">template <class InputIterator> map(InputIterator first, InputIterator last, const Compare& comp = Compare(), const Allocator& = Allocator())</a><br>
<a href="map.htm#map3">map(const map<Key,T,Compare,Allocator>& x)</a><br>
<a href="map.htm#map4">~map()</a><br>
<a href="common.htm#maxsize">size_type max_size() const</a><br>
<a href="common.htm#rbegin">reverse_iterator rbegin()</a><br>
<a href="common.htm#rbegin">const_reverse_iterator rbegin() const</a><br>
<a href="common.htm#rend">reverse_iterator rend()</a><br>
<a href="list.htm#resize">void resize(size_type Sz, T C = T())</a><br>
<a href="common.htm#rend">const_reverse_iterator rend() const</a><br>
<a href="common.htm#size">size_type size() const</a><br>
<a href="map.htm#swap">void swap(map<Key,T,Compare,Allocator>&)</a><br>
<a href="assoc.htm#upper">iterator upper_bound(const key_type& x) const</a><br>
<a href="assoc.htm#upper">const_iterator upper_bound(const key_type& x) const</a><br>
</pre>
<h2>Operators</h2>
reference operator[](const key_type& x);
map<Key,T,Compare,Allocator>& operator=(const map<Key,T,Compare,Allocator>& x);
<a href="map.htm#example"><h2>Example</h2></a><br>
<a name="desc"><h3>Class Description</h3></a>
<p>
A Map container is a special type of <i>'set'.</i> The map collection, also called a dictionary or
associative array, is used to create a collection of related pairs. The map collection associates
the elements of one set to the elements of another set. The map collection is an indexed structure
similar to a vector. Where a vector uses integers as the index values, a map collection can use
any type as the index value. The map collection consists of related ordered pairs. The first
element of the pair serves as the key and the other element the value. The value can be accessed
by using the key as the index value within a subscript operator. The key and the value can be of
the same type or any mix of types. Map containers are associative structures where the key is one
dimension and the value is another. It can be considered multidimensional. Maps and multimaps are
mathematical notions that implement the concept of relations. A map associates the elements in one
set with the elements in another set
</p>
<hr>
<pre>
<a name="swap">Method swap()</a>
Access Public
Classification Modifier
Syntax void swap(map<Key,T,Compare,Allocator>& X)
Parameters X is the map to be swapped with the contents of the current map.
Return X is the map to be swapped.
</pre>
<h3>Description</h3>
<p>
The swap() method swaps the contents of the current map with map X.
</p>
<hr>
<pre>
<a name="map1">Method map()</a>
Access Public
Classification Constructor
Syntax explicit map(const Compare& Comp = Compare(), const Allocator &X = Allocator())
Parameters Comp is the function object that will be used to order the map.
X is a allocator object.
Return None.
</pre>
<h3>Description</h3>
<p>
The map() method constructs an empty set container.
</p>
<hr>
<pre>
<a name="map2">Method map()</a>
Access Public
Classification Constructor
Syntax template <class InputIterator> map(InputIterator first, InputIterator last,const Compare& Comp = Compare(), const Allocator&X = Allocator())
Parameters elements from the range [first,last) will be used to construct the map. X is a allocator object.
Comp is the function object that will be used to order the map.
Return None.
</pre>
<h3>Description</h3>
<p>
The map() method constructs a map that contains copies of the objects that are pointed to by the
iterators in the range [first,last].
</p>
<hr>
<pre>
<a name="map3">Method map()</a>
Access Public
Classification Constructor
Syntax map(const map<Key,Compare,Allocator>& X)
Parameters X is the map that will be used to construct the new map.
Return None.
</pre>
<h3>Description</h3>
<p>
The map() method constructs a new set from map X.
</p>
<hr>
<pre>
<a name="map4">Method map()</a>
Access Public
Classification Destructor
Syntax ~map()
Parameters None.
Return None.
</pre>
<h3>Description</h3>
<p>
The ~map() method destructs a map object.
</p>
<hr>
<h2><a name="example">Example</a></h2>
<img src="lego.gif" left>
<pre>
// demonstrates how map elements can be accessed
// using associations. The last loop demonstrates
// how a set iterator can be used as a association
// element for a map.
#include <string>
#include <map>
#include <set>
#include <iostream>
void main(void)
{
map<string,string,less<string> > MapA;
pair<string,string> Group[4];
Group[0].first = "orange";
Group[0].second = "clock work";
Group[1].first = "red";
Group[1].second = "Herring";
Group[2].first = "white";
Group[2].second = "Knight";
Group[3].first = "silver";
Group[3].second = "bullet";
MapA["blue"] = "bird";
MapA["brown"] = "bear";
MapA["green"] = "goblin";
map<string,string,less<string> > MapB(MapA);
cout << MapB["green"] << endl;
cout << MapB["blue"] << endl;
cout << MapB["brown"] << endl;
map<string,string,less<string > > MapC(Group,Group+4);
set<string,less<string> > SetA;
SetA.insert("white");
SetA.insert("silver");
SetA.insert("orange");
SetA.insert("red");
set<string,less<string> >::iterator P = SetA.begin();
while(P != SetA.end())
{
cout << *P << " " << MapC[*P] << endl;
P++;
}
}
</pre>
<hr>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -