I am confused about function of std::erase
in C++.
The following code gets the same output before and after std::erase
is called.But if iterate through the list after performing std::erase
then in output the erased value is not showing.
Help me understand std::erase
.
#include<bits/stdc++.h>
using namespace std;
int main()
{
list<int> v;
v.push_back(12);
v.push_back(10);
v.push_back(20);
list<int>::iterator it;
it = v.begin();
printf("%u %d\n", it, *it);
v.erase(it);
printf("%u %d\n", it, *it);
for(it= v.begin(); it!= v.end(); it++)
cout<< *it<<" ";
return 0;
}
Output:
"Memory address" 12
"Memory Address" 12
10 20