displaying vectors

Hi,

When printing all the elements of a vector, specifically strings, I use

1
2
for(size_t n = 0; n < myvector.size(); n++)
		cout << myvector[n] << " ";


Below shows an alternate way from a website I came across:
1
2
3
4
5
6
7
8
// ... (populate the vector)
 
for (vector<string>::iterator n = names.begin();
                              n != names.end();
                              ++n)
{
    cout << "Name: " << *n << endl;
}


Any difference in performance, etc?
The first one is much faster because it doesn't call std::endl()

As for the loops, they are equivalent (although, in practice, I've seen compilers that optimize the iterator-based loop a tiny bit better)
Thanks
Topic archived. No new replies allowed.