Reputation: 161
std::list.insert inserts an element before the iterator position. How can I insert an element after an iterator position.
Upvotes: 16
Views: 19947
Reputation: 95
Use the function:
itr = mylist.insert_after(Itr, value)
It will insert the value
after the position pointed by itr
.
Upvotes: 1
Reputation: 39650
that's what list::insert
does. Just increment your iterator before inserting your value:
if (someIterator != someList.end()) {
someIterator++;
}
someList.insert(someIterator, someValue);
Upvotes: 22