Return to Topic Menu | Computer Science Main Page | MathBits.com | Terms of Use | Resource CD

 

Using apvector Variables

 

length( ) function

 - returns the size of the array (vector).

apvector <double> passwords(100);
int len;
. . .
len = passwords.length( );      
// len is set to 100

 

assignment operator
b = a

 - copies vector a into vector b.  The size of b is properly adjusted to match the size of a
 

resize (...) function

 

 - lets you change the size of the array.  This function may also be used when the size of the array is not known in advance, but is entered by the user or read from a file.

apvector <double> averages;
int number ;
. . .
cout<<"Enter number of averages: ";
cin>>number ;
averages.resize(number);

An empty array was declared.  An empty array MUST be resized in order to be used.

If you resize an array and the new size is smaller than the original size, the vector's tail is chopped off and the tail elements are LOST!!!!!