天天看點

c++ accumulate

#include <bits/stdc++.h>

using namespace std;
vector<string> v; vector<int> vs;
int a[11];

int main(int argc, char const *argv[]) {
  v.push_back("123"); v.push_back("456"); v.push_back("asd");
  cout << accumulate(v.begin(), v.end(), string("")) << endl;
  vs.push_back(1); vs.push_back(3);
  cout << accumulate(vs.begin(), vs.end(), 0) << endl;
  for (int i = 1; i <= 10; i++) a[i] = i;
  cout << accumulate(a + 1, a + 10 + 1, 0) << endl;
}      
struct node {int x, y;}e[11];
for (int i = 1; i <= 10; i++) e[i].x = e[i].y = i;
cout << accumulate(e + 1, e + 10 + 1, 0, [](int a, node w) {return a + w.x + w.y;}) << endl;