Sign in to follow this  
flounder

vector iterator

Recommended Posts

in my program im using the find(vec.begin,vec.end,search) command to find where an element is in a vector, but find() only returns an iterator. is there a way to get the position of the element that the iterator is pointing to?

Share this post


Link to post
Share on other sites
Just so you know, you can get the value of the element from the iterator by dereferencing it:-

vector<int>::iterator it;
int val = *it;

I'm not personally sure how you do what you want though.

Share this post


Link to post
Share on other sites
No, you can't get it directly from the iterator. Why do you want to know the element's index?
There certainly is another way to do it, if of course it really is necessary.

Share this post


Link to post
Share on other sites
thanks, std::distance() works fine. Why would i need it? I'm making a burrwos wheeler transformer and i think it would be quicker to use find() to find a pattern in the block of transformed text than to search the lines of the block.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this