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.)

Recommended Answers

All 2 Replies

myIter - myVec.begin() would be a start.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.