최신 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<<"Sum of all the elements are:"<<endl;
cout<<accumulate(v.begin(),v.end(),0);
} 출력
Sum of all the elements are: 25