stl向量
Given a vector and we have to find the sum of the elements using C++ program.
给定一个向量,我们必须使用C ++程序找到元素的总和。
求向量元素之和 (Finding sum of vector elements)
To find the sum of the elements, we can use accumulate() function which is defined in <numeric> header in C++ standard template library. It accepts the range of the iterators in which we have to find the sum of the elements; it also accepts a third parameter which can be used to provide an initial value of the sum.
要查找元素的总和 ,可以使用在C ++标准模板库的<numeric>标头中定义的accumulate()函数 。 它接受迭代器的范围,我们必须在其中找到元素的总和。 它还接受第三个参数,该参数可用于提供总和的初始值。
Note: To use vector – include <vector