It doesn’t appear to (sample program), but can I be sure?
// does resizing an STL vector erase/invalidate it's previous contents?
#include <stdio.h>
#include <vector>
using namespace std ;
void print( vector<int>& t )
{
for( int i = 0 ; i < t.size() ; i++ )
printf( "%d ", t[i] ) ;
puts("");
}
int main()
{
vector<int> t ;
t.resize( 12,9999 ) ;
print(t) ;
t.resize( 15, 10000 ) ;
print(t) ;
}
Resizing an STL vector may require reallocating the underlying storage. This may cause any number of elements to be destroyed and recreated, and all iterators are invalidated. Accessing an invalidated iterator is a common source of errors when using the STL.
The contents of each element will be the same, unless the copy constructor doesn’t work.