Demonstrate istream_iterator - C++ STL Algorithm

C++ examples for STL Algorithm:istream_iterator

Description

Demonstrate istream_iterator

Demo Code

#include <iostream>
#include <list>
#include <algorithm>
#include <iterator>
using namespace std;
int main()//from  www  .j av  a  2  s.  c  o  m
{
   list<float> fList(5);           // uninitialized list
   cout << "\nEnter 5 floating-point numbers: ";
   // istream iterators
   istream_iterator<float> cin_iter(cin);   // cin
   istream_iterator<float> end_of_stream;   // eos
   // copy from cin to fList
   copy( cin_iter, end_of_stream, fList.begin() );
   cout << endl;                   // display fList
   ostream_iterator<float> ositer(cout, "--");
   copy(fList.begin(), fList.end(), ositer);
   cout << endl;
   return 0;
}

Result


Related Tutorials