abraxas334
February 12th, 2011, 02:05 PM
This may be a very silly question about iterators.
I have a vector defined like this:
using namespace std;
vector<int> Vertex (30);
//then i fill the vector with some elements
//Vertex is sorted and unique;
//now I need to find the position of an element with a certain value in the vector
vector<int>::iterator it;
it = find(Vertex.begin(), Vertex.end(), 25)
I want to know at which point in the vector 25 appears, i.e. which value of i between 0 and 29, if I was to go over the vector in this style:
for (int i = 0; i<Vertex.size(); i++)
{
cout<<Vertex[i]<<endl;
}
if i do a cout<<iterator<<*it<<endl; it is is the same as cout<<Vertex[i]<<endl; but what I really want to know for which "i" the iterator returns my value of 25. Is there a simple way of doing it, because i need the position as an int value in order to pass it to a function, otherwise I'll have to rewrite the entire function
I have a vector defined like this:
using namespace std;
vector<int> Vertex (30);
//then i fill the vector with some elements
//Vertex is sorted and unique;
//now I need to find the position of an element with a certain value in the vector
vector<int>::iterator it;
it = find(Vertex.begin(), Vertex.end(), 25)
I want to know at which point in the vector 25 appears, i.e. which value of i between 0 and 29, if I was to go over the vector in this style:
for (int i = 0; i<Vertex.size(); i++)
{
cout<<Vertex[i]<<endl;
}
if i do a cout<<iterator<<*it<<endl; it is is the same as cout<<Vertex[i]<<endl; but what I really want to know for which "i" the iterator returns my value of 25. Is there a simple way of doing it, because i need the position as an int value in order to pass it to a function, otherwise I'll have to rewrite the entire function