In C++, the STL (standard template library) "vector" type is a rich-featured template class. This means it can hold objects of almsot any type, controlling them in a rich way to do searches, sorts, etc. There are other container types as well, and most support the same operations. The differences are in the speed and optimization you get from each (searches are usually vastly different). Also see "map" and "multimap" and other associative containers.
A simple array type ( int[ ] or similar) is akin to a C array, where a fixed number of items is reserved on the heap (or stack) and you must flip through them manually with an index. There are no methods on these types for searches, inserts, deletes, etc because they are not a true "container" but simply a sequence of similar objects in memory. You must write the code to search them.
Look up the vector in the STL (see sources) and try using some of the methods it provides. There is a cost associated with using a template class from the STL, and sometimes this matters (don't use one unless you need the functionality it provides). But if you need to do searches, a vector or similar template can be a great help. Number one benefit is you don't have to debug you're code for doing set operations, you can trust the STL.
2006-11-17 03:22:11
·
answer #1
·
answered by WickedSmaht 3
·
0⤊
0⤋
the authentic massive difference is that vectors dynamically allocate memory and modify and in truth, arrays are have static allotted memory that cannot be adjustments. for this reason, an integer array(5) will continually include 5 integers yet a vector can upload extra positions and include as many as your pc memory helps.
2016-11-25 00:32:46
·
answer #2
·
answered by Anonymous
·
0⤊
0⤋
A vector is an STL encapsulation, a container class, it can be thought of as a dynamic array.
An array is a fixed set of something.
2006-11-17 03:20:06
·
answer #3
·
answered by Chris H 6
·
0⤊
0⤋
i guess the difference would be the same as that in java (I dont know any C++), and the difference would be that an array once declared, the size of the same cant be increased, but the size of a vector automatically adjusts itself if you keep adding more elements to it
2006-11-17 03:17:23
·
answer #4
·
answered by Neil 5
·
0⤊
0⤋