fork(1) download
  1. #include <iostream>
  2. #include <numeric>
  3. #include <algorithm>
  4. #include <list>
  5. #include <iterator>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10. list<int> a(5);
  11. iota(a.begin(), a.end(), 1);
  12.  
  13. for (int i = 6; i <= 10; ++i)
  14. {
  15. back_inserter(a) = i; // returns an iterator
  16. }
  17.  
  18. for_each(a.begin(), a.end(), [](int i) { cout << i << ' '; });
  19. cout << endl;
  20.  
  21. return 0;
  22. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
1 2 3 4 5 6 7 8 9 10