954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Vector hell

Hi guys i'm tyring to delete some elements from a vector. I am trying to delete from 0 to k-1 and from k to the end. That means in theory that only element k should remain.

1) cell[i][j].erase(cell[i][j].begin(),k-1);
2) cell[i][j].erase((cell[i][j].begin()+k+1),(cell[i][j].end()));


line 2 does not give me an error, however line one gives me:

error C2664: 'std::vector<_Ty>::iterator std::vector<_Ty>::erase(std::vector<_Ty>::iterator,std::vector<_Ty>::iterator)' : cannot convert parameter 2 from 'int' to 'std::vector<_Ty>::iterator'
with
[
_Ty=int
]
and
[
_Ty=int
]
No constructor could take the source type, or constructor overload resolution was ambiguous

does anyone have any ideas? Thanks

Lutzee
Newbie Poster
12 posts since Sep 2006
Reputation Points: 19
Solved Threads: 0
 

This is because erase call expects both the parameters to be iterators while in your first line you have called the erase function with an integer argument. Make appropriate change to the second argument of your first line to an iterator and it should be fine.

*Hint: Use the same trick you used in the second line. *

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You