I cannot figure why I'm getting an error when running the following simple program
#include <iostream>
#include <vector>
int main(int argc, char** argv) {
std::vector<int> v{ 1,2,3,4,5 };
std::vector<int>::iterator it1 = v.end();
auto it_tmp = v.insert(v.end(), 6);
std::vector<int>::iterator it2 = v.end();
std::cout << (it1 == it2) << std::endl;
return 0;
}
The iterators it1
and it2
are incompatible, so I was wondering what could possible be the issue. Iterators are incompatible if they belong to different containers, I would then assume in my case one of the two gets invalidated or something like that (I've also try to change v.end
with v.begin()
for both it1
and it2
, it doesn't make any difference).
Thank you.