vector.begin, vector.end returns the iterators : vector iterator « Vector « C++






vector.begin, vector.end returns the iterators

   
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


int main(void)
{
    const int VECTOR_SIZE = 8 ;
    typedef vector<int> IntVector ;
    typedef IntVector::iterator IntVectorIt ;
    IntVector Numbers(VECTOR_SIZE) ;

    IntVectorIt start, end, it ;

    Numbers[0] = 4;
    Numbers[1] = 1;
    Numbers[2] = 7;
    Numbers[3] = 3;
    Numbers[4] = 1;
    Numbers[5] = 6;
    Numbers[6] = 9;
    Numbers[7] = 10;

    start = Numbers.begin() ;   
    end = Numbers.end() ;       

    for(it = start; it != end; it++)
        cout << *it << " " ;

    random_shuffle(start, end) ;

    for(it = start; it != end; it++)
        cout << *it << " " ;
}
  
    
    
  








Related examples in the same category

1.Display contents of vector through an iterator
2.Use const_iterator to loop through the vector
3.Change contents of vector through an iterator
4.interator operator for vector
5.Loop through all elements in a vector in reverse order by using rbegn, rend
6.const_iterator from different containers