What would have better performance, a stl vector, or a dynamic array that's just realloc'd everytime I want to add something to it?
Stl vectors have insertion in amortized constant time (because reallocation is not done all the time and reservations occur by factor 1.5 (minimum)).
Therefore according to your description, vectors will be massively faster than reallocating all the time
Would using vectors::iterator be faster then using a for loop on an array?
In the general case: exactly identical.
However certain STL implementations generate checks in debug mode that can considerably slow down the use of container iterators.
(note most implementations implement vector/string iterators as a typedef to value_type*
)
And if someone could explain why, that would be great.