Use indexer to add elements to a vector
#include <iostream> #include <cassert> #include <algorithm> #include <vector> #include <deque> using namespace std; int main() { vector<int> vector1(20); for (int i = 0; i < 20; ++i) vector1[i] = i; vector<int>::iterator pos; for (pos=vector1.begin(); pos!=vector1.end(); ++pos) { cout << *pos << ' '; } return 0; } /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 */