programming-examples/c++/Others/Assign Items in int array to vector.cpp
2019-11-15 12:59:38 +01:00

24 lines
369 B
C++

Assign Items in int array to vector
#include <iostream>
#include <vector>
#include <cassert>
#include <numeric> // for accumulate
using namespace std;
int main()
{
int x[5] = {2, 3, 5, 7, 11};
vector<int> vector1(&x[0], &x[5]);
int sum = accumulate(vector1.begin(), vector1.end(), 0);
cout << sum << endl;
return 0;
}
/*
28
*/