Zebra0.com

cpp vectorsComparison of array and vector

Comparison of array and vector

This short program shows an array and a vector with the exact same elements. Both use a for loop to display the contents.

There is no easy way to initialize the contents of a vector. If you are using a fixed number of elements such as the names of the months, it is easier and more efficient to use an array. If you are reading from a file and are not sure how many records are in the file, use a vector.