Fastest way to reset every value of std::vector<int> to 0

Matthieu Riegler picture Matthieu Riegler · Jan 13, 2012 · Viewed 158.6k times · Source

What's the fastest way to reset every value of a std::vector<int> to 0 and keeping the vectors initial size ?

A for loop with the [] operator ?

Answer

Cat Plus Plus picture Cat Plus Plus · Jan 13, 2012
std::fill(v.begin(), v.end(), 0);