#include
#include
int main() {
std::vector vec;
for (int i = 0; i < 42; ++i) {
vec.push_back(i);
Once you call std::vector::push_back or most non-const function for that matter the iterators are invalidated (When the new size exceeds the current capacity of the vector which causes the memory to be re-allocated internally)
You can find some good references on how standard containers or iterators work in general. I hope that gets you started!