📄 set.htm
字号:
<html>
<head>
<title> The set Class</title>
</head>
<body bgcolor="#FFFFFF">
<img src="setban.gif">
<pre>
<font size=5>Class Name</font> set
<font size=5>Header File</font> <set>
<font size=5>Classification</font> Container
</pre>
<a href="set.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="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="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="set.htm#set1">explicit set(const Compare& comp = Compare(), const Allocator& = Allocator())</a><br>
<a href="set.htm#set2">template <class InputIterator> set(InputIterator first, InputIterator last,const Compare& Comp = Compare(), const Allocator&X = Allocator())</a><br>
<a href="set.htm#set3">set(const set<Key,Compare,Allocator>& X)</a><br>
<a href="set.htm#set4">~set()</a><br>
<a href="common.htm#size">size_type size() const</a><br>
<a href="set.htm#swap">void swap(set<Key,Compare,Allocator>& X)</a><br>
<a href="assoc.htm#upper">iterator upper_bound(const key_type& x) const</a><br>
</pre>
<h2>Operators</h2>
set<Key,Compare,Allocator>& operator=(const set<Key,Compare,Allocator>& x);
<a href="set.htm#example"><h2>Example</h2></a><br>
<hr>
<a name="desc"><h3>Class Description</h3></a>
<p>
A set container can be used to represent a collection of people, places, things, or ideas.
An important characteristic of sets is that they only allow an object to be included once in the set.
That is each element must have a unique key.
</p>
<hr>
<pre>
<a name="swap">Method swap()</a>
Access Public
Classification Modifier
Syntax void swap(set<Key,Compare,Allocator>& X)
Parameters X is the set to be swapped with the contents of the current set.
Return X is the set to be swapped.
</pre>
<h3>Description</h3>
<p>
The swap() method swaps the contents of the current set with set X.
</p>
<hr>
<pre>
<a name="set1">Method set()</a>
Access Public
Classification Constructor
Syntax explicit set(const Compare& Comp = Compare(), const Allocator &X = Allocator())
Parameters Comp is the function object that will be used to order the set.
X is a allocator object.
Return None.
</pre>
<h3>Description</h3>
<p>
The set() method constructs an empty set container.
</p>
<hr>
<pre>
<a name="set2">Method set()</a>
Access Public
Classification Constructor
Syntax template <class InputIterator> set(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 set. X is a allocator object.
Comp is the function object that will be used to order the set.
Return None.
</pre>
<h3>Description</h3>
<p>
The set() method constructs a set that contains copies of the objects that are pointed to by the
iterators in the range [first,last].
</p>
<hr>
<pre>
<a name="set3">Method set()</a>
Access Public
Classification Constructor
Syntax set(const set<Key,Compare,Allocator>& X)
Parameters X is the set that will be used to construct the new set.
Return None.
</pre>
<h3>Description</h3>
<p>
The set() method constructs a new set from set X.
</p>
<hr>
<pre>
<a name="set4">Method set()</a>
Access Public
Classification Destructor
Syntax ~set()
Parameters None.
Return None.
</pre>
<h3>Description</h3>
<p>
The ~set() method destructs a set object.
</p>
<hr>
<a name="example"></a>
<img src="lego.gif">
<pre>
#include <set>
#include <iostream>
using namespace std;
void main(void)
{
set<int, less<int> > M;
M.insert(1960);
M.insert(1952);
M.insert(1771);
M.insert(1812);
M.insert(1960);
M.insert(2000);
set<int, less<int> >::iterator N= M.begin();
cout << "Number Of Elements " << M.size() << endl;
while(N != M.end())
{
cout << *N << endl;
N++;
}
}
</pre>
<hr>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -