用C ++中的带有硬编码元素初始化std :: vector的最简单方法是什么?
在现代C++[11,14,…]中,向量通过以下方式初始化
std::vector<int> vec = {1,2,3};算法
Begin Initialize the vector v. Using accumulate, sum up all the elements of the vector v is done. Print the result. End.
这是总结向量元素的简单示例:
示例
#include<iostream>
#include<vector>
#include<numeric>
using namespace std;
int main() {
vector<int> v = {2,7,6,10};
cout<<"所有元素的总和是:"<<endl;
cout<<accumulate(v.begin(),v.end(),0);
}输出结果
所有元素的总和是: 25
热门推荐
5 初八的祝福语简短
10 老板生日祝福语简短语
11 爱小姨文案祝福语简短
12 冬季祝福语大全 简短的
13 生日哥哥祝福语简短独特
14 宝宝祝福语诗意简短 古文
15 满月红包英文祝福语简短
16 致姐姐生日祝福语简短
17 给新年祝福语简短独特
18 送礼祝福语男性生日简短