for(int i=0,k=0;i<10;++i)
{
v.push_back(++k);
}
// v contains 1 to 10
for(pos1 = v.begin(); pos1 != v.end() ; ++pos1)
{
pos2 = find(v.begin(),v.end(),1);
if(pos2 != v.end())
{
v.erase(pos2);
// pos1 = v.begin(); // ----------- line 1
}
cout<<*pos1<<"\n"; // if delete no. 1 i.e begin this statement terminates proagram -------line 2
}
}
above proagram works fine for deletion of any noumber from 2 to 10 ,
but when i delete 1 (i.e. 1'st position) proagram terminates at line 2.
how ever if i uncomment line 1 proagram works. (why ?). i.e. i need to assign begin of vector again ( i think i shoud not
need this . after deleting no. 1 , *pos1 should print no. 2 ) .
can any one help ? .
i am using microsoft visual studio 2005.