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

📄 vector.html

📁 指导程序员合理、高效的进行标准模板库编程。
💻 HTML
📖 第 1 页 / 共 2 页
字号:
Creates an empty vector.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>vector(size_type n)</tt>
</TD>
<TD VAlign=top>
 <A href="Sequence.html">Sequence</A>
</TD>
<TD VAlign=top>
Creates a vector with <tt>n</tt> elements.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>vector(size_type n, const T&amp; t)</tt>
</TD>
<TD VAlign=top>
 <A href="Sequence.html">Sequence</A>
</TD>
<TD VAlign=top>
Creates a vector with <tt>n</tt> copies of <tt>t</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>vector(const vector&amp;)</tt>
</TD>
<TD VAlign=top>
 <A href="Container.html">Container</A>
</TD>
<TD VAlign=top>
The copy constructor.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
template &lt;class <A href="InputIterator.html">InputIterator</A>&gt;
vector(InputIterator, InputIterator)
<A href="#1">[1]</A>
</pre>
</TD>
<TD VAlign=top>
 <A href="Sequence.html">Sequence</A>
</TD>
<TD VAlign=top>
Creates a vector with a copy of a range.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>~vector()</tt>
</TD>
<TD VAlign=top>
 <A href="Container.html">Container</A>
</TD>
<TD VAlign=top>
The destructor.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>vector&amp; operator=(const vector&amp;)</tt>
</TD>
<TD VAlign=top>
 <A href="Container.html">Container</A>
</TD>
<TD VAlign=top>
The assignment operator
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>void reserve(size_t)</tt>
</TD>
<TD VAlign=top>
<tt>vector</tt>
</TD>
<TD VAlign=top>
See below.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>reference front()</tt>
</TD>
<TD VAlign=top>
 <A href="Sequence.html">Sequence</A>
</TD>
<TD VAlign=top>
Returns the first element.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>const_reference front() const</tt>
</TD>
<TD VAlign=top>
 <A href="Sequence.html">Sequence</A>
</TD>
<TD VAlign=top>
Returns the first element.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>reference back()</tt>
</TD>
<TD VAlign=top>
 <A href="BackInsertionSequence.html">Back Insertion Sequence</A>
</TD>
<TD VAlign=top>
Returns the last element.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>const_reference back() const</tt>
</TD>
<TD VAlign=top>
 <A href="BackInsertionSequence.html">Back Insertion Sequence</A>
</TD>
<TD VAlign=top>
Returns the last element.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>void push_back(const T&amp;)</tt>
</TD>
<TD VAlign=top>
 <A href="BackInsertionSequence.html">Back Insertion Sequence</A>
</TD>
<TD VAlign=top>
Inserts a new element at the end.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>void pop_back()</tt>
</TD>
<TD VAlign=top>
 <A href="BackInsertionSequence.html">Back Insertion Sequence</A>
</TD>
<TD VAlign=top>
Removes the last element.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>void swap(vector&amp;)</tt>
</TD>
<TD VAlign=top>
 <A href="Container.html">Container</A>
</TD>
<TD VAlign=top>
Swaps the contents of two vectors.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
iterator insert(iterator pos,
                const T&amp; x)
</pre>
</TD>
<TD VAlign=top>
 <A href="Sequence.html">Sequence</A>
</TD>
<TD VAlign=top>
Inserts <tt>x</tt> before <tt>pos</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
template &lt;class <A href="InputIterator.html">InputIterator</A>&gt;
void insert(iterator pos,
            InputIterator f, InputIterator l)
<A href="#1">[1]</A>
</pre>
</TD>
<TD VAlign=top>
 <A href="Sequence.html">Sequence</A>
</TD>
<TD VAlign=top>
Inserts the range <tt>[first, last)</tt> before <tt>pos</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
void insert(iterator pos, 
            size_type n, const T&amp; x)
</pre>
</TD>
<TD VAlign=top>
 <A href="Sequence.html">Sequence</A>
</TD>
<TD VAlign=top>
Inserts <tt>n</tt> copies of <tt>x</tt> before <tt>pos</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>iterator erase(iterator pos)</tt>
</TD>
<TD VAlign=top>
 <A href="Sequence.html">Sequence</A>
</TD>
<TD VAlign=top>
Erases the element at position <tt>pos</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>iterator erase(iterator first, iterator last)</tt>
</TD>
<TD VAlign=top>
 <A href="Sequence.html">Sequence</A>
</TD>
<TD VAlign=top>
Erases the range <tt>[first, last)</tt>
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>void clear()</tt>
</TD>
<TD VAlign=top>
 <A href="Sequence.html">Sequence</A>
</TD>
<TD VAlign=top>
Erases all of the elements.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
bool operator==(const vector&amp;, 
                const vector&amp;)
</pre>
</TD>
<TD VAlign=top>
 <A href="ForwardContainer.html">Forward Container</A>
</TD>
<TD VAlign=top>
Tests two vectors for equality.  This is a global function, not
   a member function.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
bool operator&lt;(const vector&amp;, 
               const vector&amp;)
</pre>
</TD>
<TD VAlign=top>
 <A href="ForwardContainer.html">Forward Container</A>
</TD>
<TD VAlign=top>
Lexicographical comparison.  This is a global function, not
   a member function.
</TD>
</tr>
</table>
<h3>New members</h3>
These members are not defined in the 
<A href="RandomAccessContainer.html">Random Access Container</A> 
and <A href="BackInsertionSequence.html">Back Insertion Sequence</A>
requirements, but are specific to <tt>vector</tt>.
<Table border>
<TR>
<TH>
Member
</TH>
<TH>
Description
</TH>
</TR>
<TR>
<TD VAlign=top>
<tt>size_type capacity() const</tt>
</TD>
<TD VAlign=top>
Number of elements for which memory has been allocated.
   <tt>capacity()</tt> is always greater than or equal to <tt>size()</tt>.
   <A href="#2">[2]</A> <A href="#3">[3]</A>
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>void reserve(size_type n)</tt>
</TD>
<TD VAlign=top>
If <tt>n</tt> is less than or equal to <tt>capacity()</tt>, this call has no effect.
    Otherwise, it is a request for allocation of additional 
    memory.  If the request is successful, then <tt>capacity()</tt> is
    greater than or equal to <tt>n</tt>; otherwise, <tt>capacity()</tt> is unchanged.
    In either case, <tt>size()</tt> is unchanged.  
    <A href="#2">[2]</A> <A href="#4">[4]</A>
</TD>
</tr>
</table>
<h3>Notes</h3>
<P><A name="1">[1]</A>
This member function relies on <i>member template</i> functions, which
at present (early 1998) are not supported by all compilers.  If your
compiler supports member templates, you can call this function with
any type of <A href="InputIterator.html">input iterator</A>.  If your
compiler does not yet support member templates, though, then the
arguments must be of type <tt>const value_type*</tt>.
<P><A name="2">[2]</A>
Memory will be reallocated automatically if more than <tt>capacity() -
size()</tt> elements are inserted into the vector.  Reallocation does
not change <tt>size()</tt>, nor does it change the values of any
elements of the vector.  It does, however, increase
<tt>capacity()</tt>, and it invalidates <A href="#5">[5]</A> any
iterators that point into the vector.
<P><A name="3">[3]</A>
When it is necessary to increase <tt>capacity()</tt>, <tt>vector</tt>
usually increases it by a factor of two.  It is crucial that the
amount of growth is proportional to the current <tt>capacity()</tt>,
rather than a fixed constant: in the former case inserting a series of
elements into a vector is a linear time operation, and in the latter
case it is quadratic.
<P><A name="4">[4]</A>
<tt>Reserve()</tt> causes a reallocation manually.  The main reason
for using <tt>reserve()</tt> is efficiency: if you know the capacity
to which your <tt>vector</tt> must eventually grow, then it is usually
more efficient to allocate that memory all at once rather than relying
on the automatic reallocation scheme.  The other reason for using
<tt>reserve()</tt> is so that you can control the invalidation of
iterators. <A href="#5">[5]</A>
<P><A name="5">[5]</A>
A vector's iterators are invalidated when its memory is reallocated.
Additionally, inserting or deleting an element in the middle of a
vector invalidates all iterators that point to elements following the
insertion or deletion point.  It follows that you can prevent a
vector's iterators from being invalidated if you use
<tt>reserve()</tt> to preallocate as much memory as the vector will
ever use, and if all insertions and deletions are at the vector's end.
<h3>See also</h3>
<A href="Deque.html">deque</A>, 
<A href="List.html">list</A>, 
<A href="Slist.html">slist</A>

<HR SIZE="6"> <FONT SIZE="-2"> Copyright &copy; 1996 Silicon Graphics, Inc.
<HR>
<TABLE BORDER=0 WIDTH="100%" >
<TR>
<TD WIDTH="33%"><FONT SIZE=-1><A HREF="index.html" >
STL</A></FONT></TD>

<TD WIDTH="33%">
<CENTER><FONT SIZE=-2>&copy; Copyright 1997-1998 CodeGuru</FONT>&nbsp;</CENTER>
</TD>

<TD WIDTH="34%">
<DIV ALIGN=right><FONT SIZE=-1>Contact : <A HREF="mailto:webmaster@codeguru.com">webmaster@codeguru.com</A>&nbsp;</FONT></DIV>
</TD>
</TR>
</TABLE>
<SCRIPT LANGUAGE="JavaScript" ><!--
var adurl = "/cgi-bin/doubleclick.cgi?";

if( self.adcategory )
	adurl += adcategory;
else
	adurl += "mfc";

if( self.parent.norefreshad )
	parent.norefreshad = false;
else if( validframes )
	parent.frames['ad'].location = adurl;



if( !validframes && nfrm == -1)
{
	var dclkPage = "www.codeguru.com/";
	if( self.adcategory )
		dclkPage += adcategory;
	else 
		dclkPage += "mfc";
//	var random = Math.random();
	document.write('<nolayer><center>');
	document.write('<iframe src="http://ad.doubleclick.net/adi/' + dclkPage + ';ord='
	 + random + '" width=470 height=62 marginwidth=0 marginheight=0 hspace=0 vspace=0 '
	 + 'frameborder=0 scrolling=no bordercolor="#000000">');
	document.write('<a href="http://ad.doubleclick.net/jump/' + dclkPage + ';ord='
	 + random + '">');
	document.write('<img src="http://ad.doubleclick.net/ad/' + dclkPage + ';ord='
	 + random + '" height=60 width=468>' + '</a>');
	document.write('</iframe>');
	document.write('</center></nolayer>');
	document.write('<layer  src="http://ad.doubleclick.net/adl/' + dclkPage + 
	 ';ord=' + random + '"></layer>');
	document.write('<ilayer visibility=hide width=468 height=83></ilayer>');
}

// -->
</SCRIPT> 
<!-- SCRIPT LANGUAGE="JavaScript" SRC="/global/fscript.js">
//
</SCRIPT --> 

<noscript>
<p align="center">
<a href="http://ad.doubleclick.net/jump/www.codeguru.com/cpp;ord=NupaNNFCY34AAHa7UT4">
<img src="http://ad.doubleclick.net/ad/www.codeguru.com/cpp;ord=NupaNNFCY34AAHa7UT4"></a>
</p>
</noscript>





</BODY>
</HTML>


⌨️ 快捷键说明

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