Horje
c++ count vector elements Code Example
c++ count vector elements
// 1.
for(std::vector<int>::iterator it = vector.begin(); it != vector.end(); ++it)
    sum_of_elems += *it;

// 2.
// #include <numeric>
sum_of_elems = std::accumulate(vector.begin(), vector.end(), 0);

// C++11 and higher
// 3.
// #include <numeric>
sum_of_elems = std::accumulate(vector.begin(), vector.end(),
                               decltype(vector)::value_type(0));

// 4.
for (auto& n : vector)
    sum_of_elems += n;




Cpp

Related
transformer in nlp Code Example transformer in nlp Code Example
circular array Code Example circular array Code Example
string c++ Code Example string c++ Code Example
c++ random float Code Example c++ random float Code Example
define type c++ Code Example define type c++ Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9