O'Reilly logo

Just Enough C/C++ Programming by Guy W. Lecky-Thompson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Vector

A vector is a type of dynamic array. It acts more or less in the same way as a regular array, except that it can be dynamically resized and contains more operators and functions to help manage the elements in the container.

A vector can be constructed in the following ways:

vector<char> my_string; // an empty vector

vector<char> my_string ( 10, '.' ); // a string of 10 x '.'

vector<char> my_other_string ( my_string ); // a copy of my_string

There are also the following operators, which all deal with various aspects of the size of the resulting array:

int nLength = my_string.size(); // how many characters? my_string.resize ( 100 ); // make bigger my_other_string.resize ( 5, '*' ); // make smaller, init. to '*' bool bIsEmpty = my_string.empty(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required