insert

Syntax:

    #include <list>
    iterator insert( iterator loc, const TYPE& val );
    void insert( iterator loc, size_type num, const TYPE& val );
    template<TYPE> void insert( iterator loc, input_iterator start, input_iterator end );

The insert() function either:

For example:

   // Create a list, load it with the first 10 characters of the alphabet
   list<char> alphaList;
   for( int i=0; i < 10; i++ ) {
     alphaList.push_back( i + 65 );
   }
 
   // Insert four C's into the list
   list<char>::iterator theIterator = alphaList.begin();
   alphaList.insert( theIterator, 4, 'C' );
 
   // Display the list
   for( theIterator = alphaList.begin(); theIterator != alphaList.end();
  theIterator++ )    {
     cout << *theIterator;
   }

This code would display:

   CCCCABCDEFGHIJ

Related Topics: assign, erase, merge, push_back, push_front, splice