Jump to content
  • Advertisement
Sign in to follow this  
flounder

vector iterator

This topic is 4501 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!