Input Iterator
Input iterator reads forward and is provided by istream
Key Facts
Gyroscopic Couple: The rate of change of angular momentum () = (In the limit).- = Moment of Inertia.
- = Angular velocity
- = Angular velocity of precession.
Blaise Pascal (1623-1662) was a French mathematician, physicist, inventor, writer and Catholic philosopher.
Leonhard Euler (1707-1783) was a pioneering Swiss mathematician and physicist.
Description
Input iterator moves only forward and may retrieve but not store values, provided byistream
.
Input iterators can read elements only once. To progress to the next value or end of sequence, you increment it (post or pre-increment).
Two input iterators are equal if they occupy the same position. But this does NOT mean that they return the same value on element access!Operations
Expression | Description |
---|---|
*i | Provides read access to the actual element |
i->m | Provides read access to a member of the actual element |
++i | Steps forward and returns new position (when not null) |
i++ | Steps forward and returns old position (when not null) |
i1==i2 | Returns if i1 is equal to i2 |
i1!=2 | Returns if i1 is not equal to i2 |
TYPE(i) | Copies iterator (copy constructor) |
References
- http://www.tenouk.com/
- Nicolai M. Josuttis: "The C++ Standard Library"
Example:
Example - istream_iterator and ostream_iterator
Problem
This program illustrates the use of the istream_iterator and ostream_iterator in conjunction with the copy algorithm to provide vector I/O.
Workings
#include <iostream> #include <vector> #include <algorithm> #include <iterator> int main() { int a[] = {1, 2, 3, 4, 5}; vector<int> v(a, a+5); cout <<"\nInitial contents of v, displayed using the copy " "algorithm to copy values from\nv to the standard output " "with the help of an ostream_iterator:\n"; copy(v.begin(), v.end(), ostream_iterator<int>(cout, " ")); cout <<"\nNow we copy some values from standard input into a vector " "\nusing the copy algorithm and an istream_iterator.\nEnter five " "integer values, followed by your end-of-file character:\n"; copy(istream_iterator<int>(cin), istream_iterator<int>(), v.begin()); cin.ignore(80, '\n'); cin.clear(); cout << "\nFinal contents of v: "; copy(v.begin(), v.end(), ostream_iterator<int>(cout, " ")); return 0; }
Solution
Output:
Initial contents of v, displayed using the copy algorithm to copy values from
v to the standard output with the help of an ostream_iterator:
1 2 3 4 5 Now we copy some values from standard input into a vector
using the copy algorithm and an istream_iterator.
Enter five integer values, followed by your end-of-file character:
2 4 6 8 10
^Z Final contents of v: 2 4 6 8 10
v to the standard output with the help of an ostream_iterator:
1 2 3 4 5 Now we copy some values from standard input into a vector
using the copy algorithm and an istream_iterator.
Enter five integer values, followed by your end-of-file character:
2 4 6 8 10
^Z Final contents of v: 2 4 6 8 10
References