User Tools

Site Tools


c_-_c_streams:ostream_iterator

C - C++ Streams - ostream_iterator

#include <algorithm>
#include <iostream>
#include <iterator>
using namespace std;
 
int sum(int val1, int val2) { return val2 + val1; }
 
int main()
{
  int array1[5] = {0, 1, 2, 3, 4};
  int array2[5] = {6, 7, 8, 9, 10};
  ostream_iterator<int> out(cout, " ");
 
  // Put sums of corresponding array1 and array2 elements into output stream:
  transform(&array1[0], &array1[5], &array2[0], out, sum);
 
  cout << endl;
 
  return 0;
}
c_-_c_streams/ostream_iterator.txt · Last modified: 2020/07/15 09:30 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki