Use indexer to add elements to a vector : vector subscript indexer « Vector « C++






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 
 */        
    
    
  








Related examples in the same category

1.Use indexer to reference elements in a vector
2.Loop thourgh all elements in a vector using <
3.Loop through all elements in a vector using operator [] instead of operator *
4.Create another vector that contains a subrange of vector.
5.Raise all values in a vector by a given percentage
6.Read double from keyboard, save it to a vector and find the max value