<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
 lang="en" dir="ltr">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>
    C++ Vectors    [C++ Reference]
  </title>

  <meta name="generator" content="DokuWiki Release 2009-12-25c &quot;Lemming&quot;" />
<meta name="robots" content="index,follow" />
<meta name="date" content="2010-03-07T11:47:32-0800" />
<meta name="keywords" content="stl,vector,start" />
<link rel="search" type="application/opensearchdescription+xml" href="/wiki/lib/exe/opensearch.php" title="C++ Reference" />
<link rel="start" href="/wiki/" />
<link rel="contents" href="/wiki/stl/vector/start?do=index" title="Index" />
<link rel="alternate" type="application/rss+xml" title="Recent Changes" href="/wiki/feed.php" />
<link rel="alternate" type="application/rss+xml" title="Current Namespace" href="/wiki/feed.php?mode=list&amp;ns=stl:vector" />
<link rel="edit" title="Edit this page" href="/wiki/stl/vector/start?do=edit" />
<link rel="alternate" type="text/html" title="Plain HTML" href="/wiki/_export/xhtml/stl/vector/start" />
<link rel="alternate" type="text/plain" title="Wiki Markup" href="/wiki/_export/raw/stl/vector/start" />
<link rel="canonical" href="http://www.cppreference.com/wiki/stl/vector/start" />
<link rel="stylesheet" media="all" type="text/css" href="/wiki/lib/exe/css.php?s=all&amp;t=custom1&amp;tseed=1272971091" />
<link rel="stylesheet" media="screen" type="text/css" href="/wiki/lib/exe/css.php?t=custom1&amp;tseed=1272971091" />
<link rel="stylesheet" media="print" type="text/css" href="/wiki/lib/exe/css.php?s=print&amp;t=custom1&amp;tseed=1272971091" />
<script type="text/javascript" charset="utf-8" ><!--//--><![CDATA[//><!--
var NS='stl:vector';var JSINFO = {"id":"stl:vector:start","namespace":"stl:vector"};
//--><!]]></script>
<script type="text/javascript" charset="utf-8" src="/wiki/lib/exe/js.php?tseed=1272971091" ></script>

  <link rel="shortcut icon" href="/wiki/lib/tpl/custom1/images/favicon.png" />

  </head>

<body>
<div class="dokuwiki">
  
  <div class="stylehead">

    <div class="breadcrumbs">
      <span class="bchead">You are here: </span><a href="../../start.html"  title="start">C++ Reference</a> &raquo; <a href="../../stl/start.html"  title="stl:start">C++ Standard Template Library</a> &raquo; <a href="../../stl/vector/start.html"  title="stl:vector:start">C++ Vectors</a>    </div>
    
  </div>


  
  
  <div class="page">

    <script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2828341-1";
urchinTracker();
</script>
    <!-- wikipage start -->
    


<h2><a name="c_vectors" id="c_vectors">C++ Vectors</a></h2>
<div class="level2">

<p>

Vectors contain contiguous elements stored as an array. 
</p>

<p>
Accessing members of a vector can be done in <a href="../../complexity.html" class="wikilink1" title="complexity">constant time</a>, appending
elements to a vector can be done in <a href="../../complexity.html" class="wikilink1" title="complexity">amortized constant time</a>, whereas locating a
specific value or inserting elements into the vector takes <a href="../../complexity.html" class="wikilink1" title="complexity">linear time</a>.

</p>
<table class="inline">
	<tr class="row0">
		<td class="col0"><a href="../../stl/vector/vector.html" class="wikilink1" title="stl:vector:vector_constructors">Constructors</a></td><td class="col1">create vectors and initialize them with some data</td>
	</tr>
	<tr class="row1">
		<td class="col0"><a href="../../stl/vector/operator.html" class="wikilink1" title="stl:vector:vector_operators">Operators</a></td><td class="col1">compare, assign, and access elements of a vector</td>
	</tr>
	<tr class="row2">
		<td class="col0"><a href="../../stl/vector/assign.html" class="wikilink1" title="stl:vector:assign">assign</a></td><td class="col1">assign elements to a vector</td>
	</tr>
	<tr class="row3">
		<td class="col0"><a href="../../stl/vector/at.html" class="wikilink1" title="stl:vector:at">at</a></td><td class="col1">return a reference to an element at a specific location</td>
	</tr>
	<tr class="row4">
		<td class="col0"><a href="../../stl/vector/back.html" class="wikilink1" title="stl:vector:back">back</a></td><td class="col1">returns a reference to last element of a vector</td>
	</tr>
	<tr class="row5">
		<td class="col0"><a href="../../stl/vector/begin.html" class="wikilink1" title="stl:vector:begin">begin</a></td><td class="col1">returns an iterator to the beginning of the vector</td>
	</tr>
	<tr class="row6">
		<td class="col0"><a href="../../stl/vector/capacity.html" class="wikilink1" title="stl:vector:capacity">capacity</a></td><td class="col1">returns the number of elements that the vector can hold</td>
	</tr>
	<tr class="row7">
		<td class="col0"><a href="../../stl/vector/clear.html" class="wikilink1" title="stl:vector:clear">clear</a></td><td class="col1">removes all elements from the vector</td>
	</tr>
	<tr class="row8">
		<td class="col0"><a href="../../stl/vector/empty.html" class="wikilink1" title="stl:vector:empty">empty</a></td><td class="col1">true if the vector has no elements</td>
	</tr>
	<tr class="row9">
		<td class="col0"><a href="../../stl/vector/end.html" class="wikilink1" title="stl:vector:end">end</a></td><td class="col1">returns an iterator just past the last element of a vector</td>
	</tr>
	<tr class="row10">
		<td class="col0"><a href="../../stl/vector/erase.html" class="wikilink1" title="stl:vector:erase">erase</a></td><td class="col1">removes elements from a vector</td>
	</tr>
	<tr class="row11">
		<td class="col0"><a href="../../stl/vector/front.html" class="wikilink1" title="stl:vector:front">front</a></td><td class="col1">returns a reference to the first element of a vector</td>
	</tr>
	<tr class="row12">
		<td class="col0"><a href="../../stl/vector/insert.html" class="wikilink1" title="stl:vector:insert">insert</a></td><td class="col1">inserts elements into the vector</td>
	</tr>
	<tr class="row13">
		<td class="col0"><a href="../../stl/vector/max_size.html" class="wikilink1" title="stl:vector:max_size">max_size</a></td><td class="col1">returns the maximum number of elements that the vector can hold</td>
	</tr>
	<tr class="row14">
		<td class="col0"><a href="../../stl/vector/pop_back.html" class="wikilink1" title="stl:vector:pop_back">pop_back</a></td><td class="col1">removes the last element of a vector</td>
	</tr>
	<tr class="row15">
		<td class="col0"><a href="../../stl/vector/push_back.html" class="wikilink1" title="stl:vector:push_back">push_back</a></td><td class="col1">add an element to the end of the vector</td>
	</tr>
	<tr class="row16">
		<td class="col0"><a href="../../stl/vector/rbegin.html" class="wikilink1" title="stl:vector:rbegin">rbegin</a></td><td class="col1">returns a reverse_iterator to the end of the vector</td>
	</tr>
	<tr class="row17">
		<td class="col0"><a href="../../stl/vector/rend.html" class="wikilink1" title="stl:vector:rend">rend</a></td><td class="col1">returns a reverse_iterator just past the beginning of the vector</td>
	</tr>
	<tr class="row18">
		<td class="col0"><a href="../../stl/vector/reserve.html" class="wikilink1" title="stl:vector:reserve">reserve</a></td><td class="col1">sets the minimum capacity of the vector</td>
	</tr>
	<tr class="row19">
		<td class="col0"><a href="../../stl/vector/resize.html" class="wikilink1" title="stl:vector:resize">resize</a></td><td class="col1">change the size of the vector</td>
	</tr>
	<tr class="row20">
		<td class="col0"><a href="../../stl/vector/size.html" class="wikilink1" title="stl:vector:size">size</a></td><td class="col1">returns the number of items in the vector</td>
	</tr>
	<tr class="row21">
		<td class="col0"><a href="../../stl/vector/swap.html" class="wikilink1" title="stl:vector:swap">swap</a></td><td class="col1">swap the contents of this vector with another</td>
	</tr>
</table>

</div>

<h3><a name="notes" id="notes">Notes:</a></h3>
<div class="level3">

<p>

Note that a boolean vector (vector&lt;bool&gt;) is a specialization of the vector template that is designed to use less memory.  A normal boolean variable usually uses 1-4 bytes of memory, but a boolean vector should use only one bit per boolean value..

</p>

</div>

    <!-- wikipage stop -->
  </div>

  <div class="clearer">&nbsp;</div>

  
  <div class="stylefoot">

    <div class="meta">
      <div class="user">
              </div>
      <!--
      <div class="doc">
        stl/vector/start.txt &middot; Last modified: 03/07/2010 11:47 by 67.86.74.226      </div>
      -->
    </div>

   
    </div></div></body>
</html>