Syntaxe:
#include <list> iterator insert( iterator loc, const T& val ); void insert( iterator loc, size_type num, const T& val ); template<T> void insert( iterator loc, input_iterator inicio, input_iterator fim );
De acordo com a versão, a funçãao insert():
Por exemplo:
// Cria uma lista e o carrega com os 10 primeiros caracteres do alfabeto list<char> alphaVector; for( int i=0; i < 10; i++ ) { alphaVector.push_back( i + 65 ); } // Insere quatro C's na lista list<char>::iterator theIterator = alphaVector.begin(); alphaVector.insert( theIterator, 4, 'C' ); // Mostra a lista for( theIterator = alphaVector.begin(); theIterator != alphaVector.end(); theIterator++ ) { cout << *theIterator; }
O código acima produz a seguinte saída:
CCCCABCDEFGHIJ
Tópicos Relacionados: assign, erase, merge, push_back, push_front, splice