Vector Iterator Not Incrementable

I try to store all generated value by pushing the values into vector.

However I encountered a debug assertion message displaying:"Vector iterator is not incremental"

Then, i try to google for solution and found out that have to use erase or delete.

So i try to implement into my function..yet facing the same issue.

Any ideas?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  void nearlystd_store(int val, vector<int> &aVec)//nearly sorted function
{
    vector<int>::iterator Iter;// a vector
    for (int i = 0; i < val; i ++)//generate from the start till desired nvalue
    {
        aVec.push_back(val - i);//push into this vector
    }

    partial_sort(aVec.begin(), aVec.begin() + (val / 2), aVec.end());//sort half in the vector

    for (Iter = aVec.begin(); Iter != aVec.end(); ++Iter)//push sorted value
    {
        aVec.push_back(*Iter);
        delete *Iter;
    }
} 
> However I encountered a debug assertion message displaying:"Vector iterator is not incremental"
¿where?


> delete *Iter;
Iter is an iterator to a vector of integers.
*Iter is an int.
you cannot perform a delete on an int
your code does not compile.

¿why do you even think that you need to use delete?
when i first got the error and google for the solution.

I see most posts suggest either to use clear,erase or delete when comes to such error.

I try to implement them in my code but didn't help solving my issue yet.
Shouldn't you be using aVec.size() instead of val on line 9?
In the loop on lines 11 through 15, you are using push_back on aVec. push_back may invalidate existing iterators, after which the iterator will be "not incrementable."

It isn't clear exactly what you're trying to accomplish since, if this weren't undefined behavior, it would be an infinite loop.
because after this, pushing the values into a vector is done..

I will pass into another function...to do another type of sorting.

As generally, i wanted to create a partially sorted values..then store into a vector...,pass the vector into another function to get all value sorted.

For example,using insertion sort,quick sort..
Topic archived. No new replies allowed.