This one may well work with some compilers/OS, and crash with others. Same code with "List" it's working fine, While using "vector" only I am facing undefined behavior output.
Is STL (vector) is safe?? 

Note: This is not a real-time code, I am just going through some sample programs that's it. 

```
#include <vector>
#include <iostream>

using namespace std;

int main() {
  vector<int> v;
  v.push_back(1);
  v.push_back(2);
  v.push_back(3);
  v.push_back(4);
  for (vector<int>::iterator i = v.begin();
       i != v.end(); i++) {
    cout << *i << endl;
    if (*i == 1) {
      v.push_back(5);
    }
  }
}

```

Output with vector:
1
0
3
4
0
0
4113
0
858851888
943206709
2617
.
.
1
2
3
4
5
5

```
#include <list>
#include <iostream>

using namespace std;

int main() {
  list<int> v;
  v.push_back(1);
  v.push_back(2);
  v.push_back(3);
  v.push_back(4);
  for (list<int>::iterator i = v.begin();
       i != v.end(); i++) {
    cout << *i << endl;
    if (*i == 1) {
      v.push_back(5);
    }
  }
}

```

Output with list:
1
2
3
4
5