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

📄 vector.htm

📁 这是关于VC++中的STL容器的资料,包括了STL容器各个类之间关系以及类的说明
💻 HTM
字号:
<html>
<head>
<title> The vector Class</title>
</head>

<body bgcolor="#FFFFFF">

<img src="vectban.gif">

<pre>
<font size=5>Class Name</font>            vector

<font size=5>Header File</font>           &lt;vector&gt;

<font size=5>Classification</font>      Container
</pre>

<a href="vector.htm#desc">Class Description</a><br>
<h1>Member Classes</h1>


<i>None</i>


<h1>Methods</h1>
<pre>
<a href="list.htm#assign1">template &lt;class InputIterator&gt; void assign(InputIterator First, InputIterator Last)</a><br>
<a href="list.htm#assign2">template &lt;class Size, class U&gt; void assign(Size n, const U& u = U())</a><br>
<a href="vector.htm#at">reference at(size_type N)</a><br>
<a href="vector.htm#at">const_reference at(size_type N) const</a><br>
<a href="vector.htm#back">reference back()</a><br>
<a href="vector.htm#back">const_reference back() const</a><br>
<a href="common.htm#begin">iterator begin()</a><br>
<a href="common.htm#begin">const_iterator begin() const</a><br>
<a href="vector.htm#capacity">size_type capacity() const</a><br>
<a href="list.htm#clear">void clear()</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="sequence.htm#erase1">iterator erase(iterator Pos)</a><br>
<a href="sequence.htm#erase2">iterator erase(iterator First, iterator Last)</a><br>
<a href="vector.htm#front">reference front()</a><br>
<a href="vector.htm#front">const_reference front() const</a><br>
<a href="list.htm#getallocator">allocator_type get_allocator() const</a><br>
<a href="sequence.htm#insert1">iterator insert(iterator position, const T& x = T())</a><br>
<a href="sequence.htm#insert2">void insert(iterator position, size_type n, const T& x)</a><br>
<a href="sequence.htm#insert3">template &lt;class InputIterator&gt; void insert(iterator Pos, InputIterator First, InputIterator Last)</a><br>
<a href="common.htm#maxsize">size_type max_size() const</a><br>
<a href="vector.htm#popback">void pop_back()</a><br>
<a href="vector.htm#pushback">void push_back(const T& X)</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="vector.htm#reserve">void reserve(size_type N)</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="vector.htm#swap">void swap(vector&lt;T,Allocator&gt;& X)</a><br>
<a href="vector.htm#vector1">explicit vector(const Allocator& = Allocator())</a><br>
<a href="vector.htm#vector2">explicit vector(size_type n, const T& value = T(),const Allocator& = Allocator())</a><br>
<a href="vector.htm#vector3">template &lt;class InputIterator&gt;vector(InputIterator First, InputIterator Last,const Allocator& = Allocator())</a><br>
<a href="vector.htm#vector4">vector(const vector&lt;T,Allocator&gt;& X)</a><br>
<a href="vector.htm#vector5">~vector()</a><br>

</pre>

<h2>Operators</h2>

vector&lt;T,Allocator&gt;& operator=(const vector&lt;T,Allocator&gt;& X);
reference operator[](size_type N);
const_reference operator[](size_type N) const;



<a href="vector.htm#example"><h2>Example</h2></a><br>
<hr>
<a name="desc"><h3>Class Description</h3></a>
<p>

Like the traditional C++ array, a vector is a container that provides  direct access to the objects
it contains.  The object oriented vector is a dynamic structure.  This means that
its size is not fixed.  The size of  the C++ vector may grow or shrink during program 
execution.  This one of  primary advantages of using the object oriented vector over
using the traditional C++ array.

</p>
<hr>

<pre>
<a name="at">Method            at()</a>

Access            Public

Classification    Accessor

Syntax            reference at(size_type N)

Parameters        N is the position in the container

Return            This method returns a reference to the object at position N in the container.

</pre>

<h3>Description</h3>
<p>
The at() method returns the object located at position N in the container.
</p>
<hr>


<pre>
<a name="back">Method            back()</a>

Access            Public

Classification    Accessor

Syntax            reference back()

Parameters        None

Return            This method returns a reference to the object at end of the container.

</pre>

<h3>Description</h3>
<p>
The back() method returns the object located at end of the container.
</p>
<hr>

<pre>
<a name="capacity">Method            capacity()</a>

Access            Public

Classification    Accessor

Syntax            size_type capacity() const

Parameters        None

Return            This method returns the largest number of objects that the container
                  can store without reallocation.

</pre>

<h3>Description</h3>
<p>
The capacity() method returns the largest number of objects that the container can store
without reallocation.
</p>
<hr>

<pre>
<a name="front">Method            front()</a>

Access            Public

Classification    Accessor

Syntax            reference front()

Parameters        None

Return            This method returns a reference to the object at the front of the container.

</pre>

<h3>Description</h3>
<p>
The front() method returns the object at the head/front of the container.
</p>
<hr>

<pre>
<a name="popback">Method            pop_back()</a>

Access            Public

Classification    Modifier

Syntax            void pop_back()

Parameters        None

Return            None

</pre>

<h3>Description</h3>
<p>
The pop_back() method removes the last object from the container.  The container must be
contain elements prior to the call to pop_back().
</p>
<hr>

<pre>
<a name="pushback">Method            push_back()</a>

Access            Public

Classification    Modifier

Syntax            void push_back(const T& X)

Parameters        X is the object to be inserted into the rear of the container.

Return            None

</pre>

<h3>Description</h3>
<p>
The push_back() method inserts an element X at the end of the container.
</p>
<hr>

<pre>
<a name="reserve">Method            reserve()</a>

Access            Public

Classification    Modifier

Syntax            void reserve(size_type N)

Parameters        N is the number of objects that the reserve method should reserve
                  space for.

Return            None

</pre>

<h3>Description</h3>
<p>
The reserve() method insures that space for N objects has been allocated for the container.
If size() == N no action is taken.  However if N > size() then the reserve method allocates
the additional space necessary.  Any pointers or references to objects in the container at
the time a reallocation takes place become invalid.
</p>
<hr>


<pre>
<a name="swap">Method            swap()</a>

Access            Public

Classification    Modifier

Syntax            void swap(vector&lt;T,Allocator&gt;& X)

Parameters        X is the vector to be swapped with the contents of the current vector.

Return            X is the vector to be swapped.

</pre>

<h3>Description</h3>
<p>

The swap() method swaps the contents of the current vector with vector X.

</p>
<hr>

<pre>
<a name="vector1">Method            vector()</a>

Access            Public

Classification    Constructor

Syntax            explicit vector(const Allocator& X = Allocator())

Parameters        X is a allocator object.

Return            None.

</pre>

<h3>Description</h3>
<p>

The vector() method constructs an empty vector container.

</p>
<hr>

<pre>
<a name="vector2">Method            vector()</a>

Access            Public

Classification    Constructor

Syntax            explicit vector(size_type N, const T& Value = T(),const Allocator& X = Allocator())

Parameters        X is a allocator object.  N is the number of objects that have been initialized
                  with value that will be inserted into the vector.

Return            None.

</pre>

<h3>Description</h3>
<p>

The vector() method constructs a vector that contains N objects that have been initialized
to value.

</p>
<hr>

<pre>
<a name="vector3">Method            vector()</a>

Access            Public

Classification    Constructor

Syntax            template &lt;class InputIterator&gt;vector(InputIterator First, InputIterator Last,const Allocator &X = Allocator())

Parameters        The range [First,Last) will be used to construct the vector object. X is an allocator object.
                
Return            None.

</pre>

<h3>Description</h3>
<p>

The vector() method constructs a vector that contains copies  of the objects that are located in the
range [First,Last).
</p>
<hr>

<pre>
<a name="vector4">Method            vector()</a>

Access            Public

Classification    Constructor

Syntax            vector(const vector&lt;T,Allocator&gt;& X)

Parameters         X is a vector used to construct a new vector.
                
Return            None.

</pre>

<h3>Description</h3>
<p>

The vector() method constructs a vector that contains a copy of vector X.
</p>
<hr>

<pre>
<a name="vector5">Method            vector()</a>

Access            Public

Classification    Destructor

Syntax            ~vector()

Parameters        None.
                
Return            None.

</pre>

<h3>Description</h3>
<p>

The ~vector() method destructs a vector object.
</p>
<hr>

<a name="example"></a>
<img src="lego.gif">
<pre>

#include &lt;algorithm&gt;
#include &lt;iostream&gt;
#include &lt;vector&gt;

using namespace std;

void main(void)
{
   vector&lt;char&gt; VectB;
   vector&lt;char&gt;::iterator P;
   VectB.push_back('B');
   VectB.push_back('@');
   VectB.push_back('#');
   VectB.push_back('Z');
   VectB.push_back('%');
   P = VectB.begin();
   P += 2;
   vector&lt;char&gt; VectA(P,VectB.end());
   int N = 0;
   for(N = 0;N &lt; VectA.size();N++)
   {
	cout &lt;&lt; VectA[N] &lt;&lt; endl;
   }
   vector&lt;char&gt;VectC(VectA);
   ostream_iterator&lt;char&gt; Out(cout," ");
   copy(VectC.begin(),VectC.end(),Out);

}
</pre>
<hr>
</body>
</html>





⌨️ 快捷键说明

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