Or login with:
istream.
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!| 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) |
#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; }
You must login to leave a messge