Input Iterators in C++


In this tutorial, we will be discussing a program to understand input iterators in C++.

Input iterators are one of the five iterators in STL being the weakest and simplest of all. They are mostly used in serial input operations where each value is read one and then the iterator moves to the next one.

Example

 Live Demo

#include <iostream>
#include <vector>
using namespace std;
int main(){
   vector<int> v1 = { 1, 2, 3, 4, 5 };
   //declaring iterator
   vector<int>::iterator i1;
   for (i1 = v1.begin(); i1 != v1.end(); ++i1) {
      //looping over elements via iterator
      cout << (*i1) << " ";
   }
   return 0;
}

Output

1 2 3 4 5

Updated on: 01-Apr-2020

254 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements