Vector Iterator of C Plus Plus Programming Language

Vector Iterator of C Plus Plus Programming Language

Instructor-svgAl-Mamun Sarkar
Apr 03 , 2020

Vector Iterator of C Plus Plus Programming Language. The following code shows how to use vector iterator in C++ programming language.

 

Code:

#include <iostream>
#include <vector>
using namespace std;

int main()
{
    vector < int > v;

    v.push_back( 1 );
    v.push_back( 2 );
    v.push_back( 3 );
    v.push_back( 4 );
    v.push_back( 5 );

    vector <int>::iterator p = v.begin();
    v.insert(v.begin() + 5, 3, 50);


    while (p != v.end()) {
        cout << *p << endl;
        p++;
    }


    return 0;
}

 

Output:

1
2
3
4
5
50
50
50

 

  • Share On:
  • fb
  • twitter
  • pinterest
  • instagram