0

If I have a vector<string> and do a find, the find returns me an iterator. How do I know what position of the vector does the iterator point to?

for example.

vector<string> myVec;
myVec.push_back( "A");
myVec.push_back( "B");
myVec.push_back( "C");
myVec.push_back( "D");
 
vector<string>myVec::iterator myIter = myVec.find(myVec.begin(), myVec.end(), "C" );
 
if ( myIter != myVec.end() )
{
   cout<<"FOUND C at position:"<<??????<<endl;
}

What do I need to do to have the cout give me 2 in this case? (Given that the vector starts with position 0, etc.)

2
Contributors
2
Replies
6
Views
11 Years
Discussion Span
Last Post by winbatch
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.