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>Qt Code:
vector<Some>::iterator ii;To copy to clipboard, switch view to plain text mode
Thanks
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>Qt Code:
vector<Some>::iterator ii;To copy to clipboard, switch view to plain text mode
Thanks
Regards
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? thanksQt Code:
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; }To copy to clipboard, switch view to plain text mode
Regards
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>?
Regards
Try:Qt Code:
std::cerr << cu - job.begin() << std::endl;To copy to clipboard, switch view to plain text mode
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
Regards
Just think. There's enough information in this thread to solve the problem.Originally Posted by mickey
mickey (20th March 2006)
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
Bookmarks