Search code examples
c++resetstdvector

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


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 ?


Solution

  • std::fill(v.begin(), v.end(), 0);