Source of iota1a.cpp


  1: //iota1a.cpp

  3: #include <iostream>
  4: #include <vector>
  5: #include <deque>
  6: #include <iterator>
  7: #include <algorithm>
  8: #include <numeric>
  9: using namespace std;

 11: int main()
 12: {
 13:     cout << "\nThis program illustrates the use of the STL iota() "
 14:         "algorithm from <numeric>\nto write an increasing "
 15:         "sequence of values to a vector and to a deque.";
 16:     cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');

 18:     vector<int> v(10);
 19:     iota(begin(v), end(v), 16); //found in <numeric>, not in <algorithm>
 20:     copy(begin(v), end(v), ostream_iterator<int>(cout, " "));
 21:     cout << endl;

 23:     deque<int> d(10, 10);
 24:     iota(begin(d)+1, end(d)-1, 31);
 25:     copy(begin(d), end(d), ostream_iterator<int>(cout, " "));
 26:     cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
 27: }