iterator erase(iterator where);
iterator erase(iterator first, iterator last);
Remarks
The first member function removes the element of the
controlled sequence pointed to by where. You use it
to remove a single element.
The second member function removes the elements of the controlled
sequence in the range [first,last). You use it to remove zero or more
contiguous elements.
Both member functions return an iterator that designates the first
element remaining beyond any elements removed, or list::end
(STL/CLR)() if no such element exists.
When erasing elements, the number of element copies is linear in the
number of elements between the end of the erasure and the nearer
end of the sequence. (When erasing one or more elements at either end
of the sequence, no element copies occur.
Exmaple
// erase all elements but end
cliext::list<wchar_t>::iterator it = c1.end();
System::Console::WriteLine("erase(begin(), end()-1) = {0}",
*c1.erase(c1.begin(), --it));
System::Console::WriteLine("size() = {0}", c1.size());
return (0);
}
自己写的方法
// if container is pointer, and you want to release memory, erase all but end
cliext::list<wchar_t>::iterator it = c1.begin();
System::Console::WriteLine("erase(begin(), end()-1) = {0}");
while (cl.empty == false)
delete it;
it = nullptr;
it = cl.erase(it);
System::Console::WriteLine("size() = {0}", c1.size());
return (0);