Friday, June 8, 2012

Vectors


The vector class supports a dynamic array. This is an array that can grow as needed.

The template specification for vector is shown here:
template <class T, class Allocator = allocator<T> > class vector
где Т это тип данных, который будет сохранен и Allocator specifies the allocator, which
defaults to the standard allocator.

vector has the following constructors:

explicit vector(const Allocator &a = Allocator( ) );
explicit vector(size_type num, const T &val = T ( ),
const Allocator &a = Allocator( ));
vector(const vector<T, Allocator> &ob);
template <class InIter> vector(InIter start, InIter end,
const Allocator &a = Allocator( ));

The first form constructs an empty vector. The second form constructs a vector that
has num elements with the value val. The value of val may be allowed to default. The
third form constructs a vector that contains the same elements as ob. The fourth form
constructs a vector that contains the elements in the range specified by the iterators
start and end.

For maximum flexibility and portability, any object that will be stored in a vector
should define a default constructor. It should also define the < and == operations.
Some compilers may require that other comparison operators be defined. (Since
implementations vary, consult your compiler's documentation for precise information.)
All of the built-in types automatically satisfy these requirements.

Declaration of vectors:

vector<int> iv; // create zero-length int vector
vector<char> cv(5); // create 5-element char vector
vector<char> cv(5, 'x'); // initialize a 5-element char vector
vector<int> iv2(iv); // create int vector from an int vector


The following comparison operators are defined for vector:
==, <, <=, !=, >, >=, []








No comments:

Post a Comment