Is there a way to use one type of iterator for another? like vector<int> iterator to vector<string> iterator,also any way iterator can be used like a interger?? coz i wanna do some mathematical manipulations on an iterator.coz i cant,i use a variable

int i;int ss=string.size()
for(int i=0;i<ss;++i)

but i was told this was not recommended in stl

Any help?

Recommended Answers

All 4 Replies

Just like you cant have pointer of one type point to another same way iterator of type cannot point to another type..

What you want to do with that?be clear.

i wanna find the square of the value of an iterator

Iterators are as pointers..(can be said)
how you will find square of a pointer..

you can add integer to an iterator..

vector<int> v;
vector<int>::iterator itr;
int value=2;
value=value*value;
itr= v.begin();
itr+=value;

you can do that.. but see to it that value is in the bounds..

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.