I found the most easiest way to find sum of all the elements of a vector
#include <iostream>
#include<vector>
using namespace std;
int main()
{
vector<int>v(10,1);
int sum=0;
for(int i=0;i<v.size();i++)
{
sum+=v[i];
}
cout<<sum<<endl;
}
In this program, I have a vector of size 10 and are initialized by 1. I have calculated the sum by a simple loop like in array.