Hi,
is possbile convert an iterator to int? I'd like retrieve, let an ii, the number (int) of element indexed from ii in the <vector>Code:
vector<Some>::iterator ii;
Thanks
Printable View
Hi,
is possbile convert an iterator to int? I'd like retrieve, let an ii, the number (int) of element indexed from ii in the <vector>Code:
vector<Some>::iterator ii;
Thanks
I am not sure what you mean, but if you want to know how many elemets the vrctor holds use ii.size().
no that!
If I have:
Are you understand? thanksCode:
vector <Job> job (10); vector <Job>::iterator ii; for (ii=job.begin(); ii != job.end(); ++ii) if ((*ii).beautiful == true) (*ii).myFunction(ii); myFunction(vector <Job>::iterator ii) { vector <Some> some (10); vector <Some>::iterator cu; cu = ii +5; //here ii may be 1,2,3 ..... (*cu).printfNumber_of_elemet_of_Some_cu_Is_refering; }
Why don't you use a QMap instead if you wnat to assign an "index" value to every element in your container?
I don't want assign an index; I'd like only to know it! Do I use <map>?
Try:Code:
std::cerr << cu - job.begin() << std::endl;
Hi, I'm sorry but I need to put it in a variabile (don't print). But Can I covert iterator to int?
I need to do something like this
Thanks
Just think. There's enough information in this thread to solve the problem.Quote:
Originally Posted by mickey
The iterator doesn't know about the contents of the container. There is a clear separation between containers, iterators, and algorithms. This is intentional. You want the element index (position) in the container. But, what if one of the elements from the container is removed. Now, the index is no longer valid ... as well as the iterator (unless it's a list iterator).
If you state what you are trying to accomplish (rather than implementation question), I'd be glad to make a suggestion.
Cheers,
Ben