Home >>C++ Standard Template Library Tutorial(STL) >C++ Input Iterator
Here are the list of the operations that are generally performed on the Input iterators:
Property | Valid Expressions |
---|---|
An input iterator is basically a copy-assignable, copy-constructible, and destructible. | X b(a); b= a; |
An input iterator can generally be compared by using a equality or inequality operator. | a==b; a!=b; |
An input iterator can generally be dereferenced. | *a; |
An input iterator can generally be incremented. | ++a; |
In the above mentioned table, 'X' is of input iterator type whereas 'a' and 'b' are the objects of an iterator type.
Here are the astonishing features of the input iterator depicted below:
Users can compare the bidirectional iterator just by using an equality or inequality operator. Whenever these both iterators point towards the exact same position then it is said that these iterators are equal, only when the given condition is fulfilled.
Here is an example of this feature that will make you understand the meaning of it:
#include <iostream> #include<vector> #include<iterator> using namespace std; int main() { vector<int> vect{10,20,30,40,50}; vector<int>::iterator itr1,itr2; itr1=vect.begin(); itr2=vect.begin()+1; if(itr1==itr2) { std::cout << "Both the iterators are equal" << std::endl; } if(itr1!=itr2) { std::cout << "Both the iterators are not equal" << std::endl; } return 0; }
The programmers can generally dereference an input iterator just by the use of a dereference operator(*).
Here is an example of this feature that will make you understand the meaning of it:
#include <iostream> #include<vector> #include<iterator> using namespace std; int main() { vector<int> vect{10,20,30,40}; vector<int>::iterator itr; itr = vect.begin(); cout<<*itr; return 0; }
The input iterators can be swapped provided that the two iterators are pointing two different locations.
Here is an example of this feature that will make you understand the meaning of it:
#include <iostream> #include<vector> #include<iterator> using namespace std; int main() { vector<int> vect{10,20,30,40}; vector<int>::iterator itr,itr1,temp; itr = vect.begin(); itr1 = vect.begin()+1; temp=itr; itr=itr1; itr1=temp; cout<<*itr<<" "; cout<<*itr1; return 0; }