You can keep the iterator returned by the find function like so:
std::vector<string>::iterator iter = std::find(nodesRefCollection.begin(), nodesRefCollection.end(), id);
if( iter != nodesRefCollection.end() )
{
int index = std::distance(nodesRefCollection.begin(), iter);
std::string cont = "|" + wayId;
legsFrame.append(cont);
legsCount ++;
isFound = true;
}