When I do:
for(i=0; i
s
This is because the vector reallocated its internal storage when it grows beyond its current capacity; after the reallocation, the address of elements may have changed.
You can avoid reallocation by reserving a big enough storage beforehand:
vectorA.reserve(size);
//vectorB.reserve(size); // this would not hurt either
for(i=0; i
One final note: if you can use C++11, emplace_back constructs your object in place, hence, without copying.