void one_number_deletion(std::list<int> &tabela)
{
std::cout << "What value would u like to delete: " << std::endl;
int value, spr=0;
std::cin >> value;
std::list<int>::iterator itr = tabela.begin();
for (itr; itr!=tabela.end();)
{
if (*itr == value) //do not increment itr in the loop there
{
spr = 1;
//tabela.erase(itr); //the problem
}
else ++itr;
}
if (spr == 0) std::cout << "Wrong table value " << std::endl;
}
The idea is that I want an user to type 10 values to the vector/list and then I want him to choose 1 value which he would like to delete. The code shows only the function, which is getting the list/vector from the main funct. Everything works correctly untill I switch tabela.erase(itr) on, then I get the error that iterator is incompatible. I have no idea how can I make this differently.