?? vector.html
字號:
Returns the <tt>n</tt>'th element.</TD></TR><TR><TD VAlign=top><tt>vector()</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>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& 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&)</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 <class <A href="InputIterator.html">InputIterator</A>>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& operator=(const vector&)</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&)</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&)</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& 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 <class <A href="InputIterator.html">InputIterator</A>>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& 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><tt>void resize(n, t = T())</tt></TD><TD VAlign=top> <A href="Sequence.html">Sequence</A></TD><TD VAlign=top>Inserts or erases elements at the end such that the size becomes <tt>n</tt>.</TD></TR><TR><TD VAlign=top><pre>bool operator==(const vector&, const vector&)</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<(const vector&, const vector&)</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, whichat present (early 1998) are not supported by all compilers. If yourcompiler supports member templates, you can call this function withany type of <A href="InputIterator.html">input iterator</A>. If yourcompiler does not yet support member templates, though, then thearguments 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 doesnot change <tt>size()</tt>, nor does it change the values of anyelements of the vector. It does, however, increase<tt>capacity()</tt>, and it invalidates <A href="#5">[5]</A> anyiterators 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 theamount of growth is proportional to the current <tt>capacity()</tt>,rather than a fixed constant: in the former case inserting a series ofelements into a vector is a linear time operation, and in the lattercase it is quadratic.<P><A name="4">[4]</A><tt>Reserve()</tt> causes a reallocation manually. The main reasonfor using <tt>reserve()</tt> is efficiency: if you know the capacityto which your <tt>vector</tt> must eventually grow, then it is usuallymore efficient to allocate that memory all at once rather than relyingon the automatic reallocation scheme. The other reason for using<tt>reserve()</tt> is so that you can control the invalidation ofiterators. <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 avector invalidates all iterators that point to elements following theinsertion or deletion point. It follows that you can prevent avector's iterators from being invalidated if you use<tt>reserve()</tt> to preallocate as much memory as the vector willever 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><!--start footer--> <HR SIZE="6"><A href="http://www.sgi.com/"><IMG SRC="surf.gif" HEIGHT="54" WIDTH="54" ALT="[Silicon Surf]"></A><A HREF="index.html"><IMG SRC="stl_home.gif" HEIGHT="54" WIDTH="54" ALT="[STL Home]"></A><BR><FONT SIZE="-2"><A href="http://www.sgi.com/Misc/sgi_info.html" TARGET="_top">Copyright © 1999 Silicon Graphics, Inc.</A> All Rights Reserved.</FONT><FONT SIZE="-3"><a href="http://www.sgi.com/Misc/external.list.html" TARGET="_top">TrademarkInformation</A></FONT><P></BODY></HTML>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -