Syntax:
#include <list> iterator insert( iterator loc, const TYPE& val ); void insert( iterator loc, size_type num, const TYPE& val ); 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++ ) { static const char letters[] = "ABCDEFGHIJ"; alphaList.push_back( letters[i] ); } // 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