Lecture 6 - Slide 3 : 40 |
We show a simple, practical example of iterators and their use
#include <iostream> #include <string> #include <vector> int main(){ using namespace std; vector<double> vd; for(int i = 1; i <= 10; i++) vd.push_back(i + i/10.0); auto it1 = vd.begin(); // auto covers the type vector<double>::iterator while(it1 != vd.end()){ cout << *it1 << " "; // 1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 11 ++it1; } }