How to access elements of a range in a vector??

S

Sachin

Hi,
I want to do a task of modifying the elements in a range, say 5th
element to 10th element.. I also know that there is a function
TRANSFORM which is used to transform the elements of any container,
say a vector, but in that function, the arguments are iterators, and
what I have is a range and not iterators to these elements.

Eg
vector<int> v;
v.transform(v.begin(),v.end(),v.begin(),modifying_func);
//this, I want to apply not from begin to end, but from say, element
at index i to index j;
//similarly, if I want to know the values in a range of vector or
list, not from begin to end, how can I //get to know that??

So is there any function or way in which I can do this operation??
 
T

tni

Hi,
I want to do a task of modifying the elements in a range, say 5th
element to 10th element.. I also know that there is a function
TRANSFORM which is used to transform the elements of any container,
say a vector, but in that function, the arguments are iterators, and
what I have is a range and not iterators to these elements.

Eg
vector<int> v;
v.transform(v.begin(),v.end(),v.begin(),modifying_func);
//this, I want to apply not from begin to end, but from say, element
at index i to index j;
//similarly, if I want to know the values in a range of vector or
list, not from begin to end, how can I //get to know that??

So is there any function or way in which I can do this operation??

An iterator to the 5th element would be:
v.begin() + 5
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top