Or login with:
ostream and inserter.
Output iterator allows you to assign new values only element-by-element. Therefore, we can't use an output iterator to iterate twice over the same range.
Note! No comparison operations are required for output iterators. You can't check if an output iterator is valid or if a "writing" was successful.| Expression | Description |
|---|---|
| *i=val | Writes val to where the iterator refers |
| ++i | Steps forward and returns new position (when not null) |
| i++ | Steps forward and returns old position (when not null) |
| TYPE(i) | Copies iterator (copy constructor) |
#include <iostream> using std::cout; using std::endl; #include <deque> // deque class-template definition #include <algorithm> // copy algorithm #include <iterator> // ostream_iterator int main() { std::deque< int > values; // create deque of type int std::ostream_iterator< int > output(cout, " "); values.push_front(2); values.push_front(3); values.push_back(1); cout << "values contains: "; // use subscript operator to obtain elements of values for ( int i = 0; i < values.size(); i++ ) cout << values[i] << ' '; cout << endl; return 0; }
You must login to leave a messge