Why use iterators over ints?

Why is it preferred to use:

1
2
3
4
for (std::vector<int>::iterator it = myvector.begin() ; it != myvector.end(); ++it)
{
    std::cout << ' ' << *it;
}


over:

1
2
3
4
for(int i = 0; i < myvector.size(); i++)
{
cout << myvector[i];
}


?
Topic archived. No new replies allowed.