Sum up of all elements of a C++ vector can be very easily done by std::accumulate method. It is defined in <numeric> header. It accumulates all the values present specified in the vector to the specified sum. code example
Example: sum of elements in c++ stl
accumulate(a.begin(), a.end(), 0)