Demonstrate ostream_iterator - C++ STL Algorithm

C++ examples for STL Algorithm:ostream_iterator

Description

Demonstrate ostream_iterator

Demo Code

#include <iostream>
#include <algorithm>
#include <list>
#include <iterator>
using namespace std;
int main()/*from  w  ww . j a  va  2  s  .  c  om*/
{
   int arr[] = { 10, 20, 30, 40, 50 };
   list<int> theList;
   for(int j=0; j<5; j++)               //transfer array to list
      theList.push_back( arr[j] );
   ostream_iterator<int> ositer(cout, ", ");  //ostream iterator
   cout << "\nContents of list: ";
   copy(theList.begin(), theList.end(), ositer);  //display list
   cout << endl;
   return 0;
}

Result


Related Tutorials