fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. template<class T> struct print : public unary_function<T, void>
  8. {
  9. print(ostream& out) : os(out) {}
  10. void operator() (T x) { os << x << ' '; }
  11. ostream& os;
  12. };
  13.  
  14. int main() {
  15. int A[] = {1, 4, 2, 8, 5, 7};
  16. const int N = sizeof(A) / sizeof(int);
  17. vector<int> v(A, A + N);
  18. for_each(v.begin(), v.end(), print<int>(cout));
  19. return 0;
  20. }
Success #stdin #stdout 0.01s 2856KB
stdin
Standard input is empty
stdout
1 4 2 8 5 7