Using iterator to fill list with data - C++ STL

C++ examples for STL:list

Description

Using iterator to fill list with data

Demo Code

#include <iostream>
#include <list>
using namespace std;
int main()// w w w .  j a  v a  2  s . c o m
{
   list<int> iList(5);      // empty list holds 5 ints
   list<int>::iterator it;  // iterator
   int data = 0;
   // fill list with data
   for(it = iList.begin(); it != iList.end(); it++)
      *it = data += 2;
   // display list
   for(it = iList.begin(); it != iList.end(); it++)
      cout << *it << ' ';
   cout << endl;
   return 0;
}

Result


Related Tutorials