

























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An in-depth exploration of iterator operations in object-oriented programming (oop). It covers various iterator categories, such as input iterators, output iterators, forward iterators, bidirectional iterators, and random-access iterators. Each category is explained with its respective operations, and examples are given using standard templates library (stl) iterators and algorithms.
Typology: Slides
1 / 33
This page cannot be seen from the preview
Don't miss anything!


























typedef std::vector< int > IntVector;
int main() {
const int SIZE = 3; int iArray[ SIZE ] = { 1, 2, 3 }; IntVector iv(iArray, iArray + SIZE); IntVector::iterator it = iv.begin(); cout << “Vector contents: ”; for ( int i = 0; i < SIZE; ++i ) cout << it[i] << ", "; return 0;
}
typedef std::set< int > IntSet;
int main() {
const int SIZE = 3; int iArray[ SIZE ] = { 1, 2, 3 }; IntSet is( iArray, iArray + SIZE ); IntSet::iterator it = is.begin(); cout << “Set contents: ”; for (int i = 0; i < SIZE; ++i) cout << it[i] << ", "; // Error return 0;
}
typedef std::set< int > IntSet;
int main() {
const int SIZE = 3; int iArray[ SIZE ] = { 1, 2, 3 }; IntSet is( iArray, iArray + SIZE ); IntSet::iterator it = is.begin(); cout << “Set contents: ”; for ( int i = 0; i < SIZE; ++i ) cout << *it++ << ", "; // OK return 0;
}
typedef std::set< int > IntSet;
int main() {
const int SIZE = 3; int iArray[ SIZE ] = { 1, 2, 3 }; IntSet is( iArray, iArray + SIZE ); IntSet::iterator it = is.end(); cout << “Set contents: ”; for (int i = 0; i < SIZE; ++i) cout << *--it << ", "; return 0;
}
Set contents: 3, 2, 1,
std::istream_iterator< int > inputIt( cin ); x = *inputIt++; y = *inputIt++; z = *inputIt; cout << "x = " << x << endl; cout << "y = " << y << endl; cout << "z = " << z << endl; return 0;
}
int main() {
int x = 5; std::istream_iterator< int > inputIt( cin ); *inputIt = x; // Error return 0;
}