vector容器中所有元素求和-accumulate
需包含头文件#include <numeric>vector<int> v(3.5,5.3);double total = accumulate(v.begin(), v.end(), 0.);其中第三个形参会影响累加的过程,如为int,则求和中均会转为int求和,故此处为获得double,改为0....
·
需包含头文件#include <numeric>
vector<int> v(3.5,5.3);
double total = accumulate(v.begin(), v.end(), 0.);
其中第三个形参会影响累加的过程,如为int,则求和中均会转为int求和,故此处为获得double,改为0.
更多推荐
已为社区贡献1条内容
所有评论(0)