i also tried to use v.erase(v.begin()+j) but i still get the "debug assertion failed error box. this function suppose to erase the duplicate. Ex : {1,2,6,8,2,8} are the elements of the vector. this function has to make it {1,2,6,8}.
void removeDup(vector<int>& v)
{
vector<int> x;
int i,j,size;
size=v.size();
for(i=0;i<size;i++)
{
for(j=1;j<size;j++)
{
if(v[i]==v[j])
{
while(v.back()!=v[j])
{
x.push_back(v.back());
v.pop_back();
}
v.pop_back();
while(!x.empty())
{
v.push_back(x.back());
x.pop_back();
}
}
}
}
}
The problem occurs inside of the if(v[i]==v[j]) when i erase 2 while function and v.pop_back() program works without an error.