Mega Code Archive

 
Categories / C++ Tutorial / STL Algorithms Helper
 

The total of the elements in a vector

#include <iostream> #include <algorithm> #include <numeric> #include <vector> using namespace std; int main() {    const int SIZE = 10;    int a1[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };    vector< int > v( a1, a1 + SIZE );    cout << "\n\nThe total of the elements in Vector v is: " << accumulate( v.begin(), v.end(), 0 );    return 0; }