Reputation: 75
I have a vector, vector<int> myvecotr
. assume that myvector={p1,p2,p3,p4}
, I need to read (p1, p2), (p2,p3),(p3,p4)
.
int t1,t2;
for(vector<int>::iterator it=myvector.begin(); it!=myvector.end();++it){
t1=*it;
t2=*(it+1); // the question is here ?
}
when I debug it using gdb,
(gdb) p *(it+1)
(gdb) Attempt to take address not located in memory
so, my question is, why *(it+1)
,sometimes, doesn't work, but ++it
works?
Any help will be greatly appreciated.
Upvotes: 3
Views: 5923