mercredi 28 octobre 2015

ostream_iterator vs cout, which one is faster? and why?

If I want to output a container's values faster, which output method should i use? ostream_iterator or cout?

For example:

vector<int>primes{2,3,5,7,11};

Case 1:

ostream_iterator<int>out{cout," "};
copy(begin(primes),end(primes),out);

Case 2:

for(int i{};i<primes.size();i++)
    cout << primes[i] << " ";

Aucun commentaire:

Enregistrer un commentaire