fork(3) download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. // Create a vector object that contains 10 elements.
  9. vector<int> v;
  10. for (int i = 1; i < 10; ++i) {
  11. v.push_back(i);
  12. }
  13.  
  14. int sum = 0;
  15. for_each(v.begin(), v.end(), [&sum](int i){ sum += i; });
  16. cout << "SUM IS: " << sum;
  17. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
SUM IS: 45