Department of Computer Science | Institute of Theoretical Computer Science | CADMO

Theory of Combinatorial Algorithms

Prof. Emo Welzl and Prof. Bernd Gärtner

// Program: vector_iterators.cpp // demonstrates vector iterators #include #include typedef std::vector::const_iterator Cvit; typedef std::vector::iterator Vit; int main() { std::vector v(5, 0); // 0 0 0 0 0 // output all elements of a, using iteration for (Cvit it = v.begin(); it != v.end(); ++it) std::cout << *it << " "; std::cout << "\n"; // manually set all elements to 1 for (Vit it = v.begin(); it != v.end(); ++it) *it = 1; // output all elements again, using random access for (int i=0; i<5; ++i) std::cout << v.begin()[i] << " "; std::cout << "\n"; return 0; }